Using CardLayout (AWT)

The AWT CardLayout layout manager arranges components in a stack, like a stack of cards.

CardLayout treats each component in the container as a card, with only one card visible at a time. The ordering of cards is determined by the container's own internal ordering of its component objects, and the first component added to a CardLayout object is the visible component when the container is first displayed.

To work with CardLayout layout manager:

  1. In the Java Beans view or Design view, select a Swing container.
  2. In the Properties view, set the layout property to CardLayout.
  3. Use the palette to drop components onto the CardLayout. The components are stacked liked cards, with only the most recently added or currently selected component visible.
  4. To affect the spacing of the components in the CardLayout, you can set the following properties in the Properties view:
    • horizontal gap - specifies the size in pixels of the left and right margins between the components and the border of the container.
    • vertical gap - specifies the size in pixels of the top and bottom margins between the components and the border of the container.
Related concepts
Layout managers and containers

(C) Copyright IBM Corporation 1999, 2004. All Rights Reserved.