CardLayout object is a layout manager for a
container. It treats each component in the container as a card.
Only one card is visible at a time, and the container acts as
a stack of cards. The first component added to a
CardLayout object is the visible component when the
container is first displayed.
The ordering of cards is determined by the container's own internal
ordering of its component objects. CardLayout
defines a set of methods that allow an application to flip
through these cards sequentially, or to show a specified card.
The CardLayout#addLayoutComponent
method can be used to associate a string identifier with a given card
for fast random access.
java.awt.Container
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | CardLayout.
A pair of component and string that represents its name. |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv int | |
| pack-priv int | |
| private static final ObjectStreamField[] | |
| private static final long | serialVersionUID
Use serialVersionUID from JDK 1.4 for interoperability. |
| pack-priv Vector | |
| pack-priv int |
| Access | Constructor and Description |
|---|---|
| public | |
| public | CardLayout(int
the horizontal gap. hgap, int the vertical gap. vgap)Creates a new card layout with the specified horizontal and vertical gaps. |
| Modifier and Type | Method and Description |
|---|---|
| public void | addLayoutComponent(Component
the component to be added. comp, Object a tag that identifies a particular
card in the layout. constraints)Implements java. Adds the specified component to this card layout's internal table of names. |
| public void | addLayoutComponent(String name, Component comp)
Implements java.
Deprecated
replaced by
addLayoutComponent(Component, Object).
If the layout manager uses a per-component string,
adds the component |
| pack-priv void | |
| public void | |
| public int | |
| public float | getLayoutAlignmentX(Container parent)
Implements java. Returns the alignment along the x axis. |
| public float | getLayoutAlignmentY(Container parent)
Implements java. Returns the alignment along the y axis. |
| public int | |
| public void | invalidateLayout(Container target)
Implements java. Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. |
| public void | |
| public void | layoutContainer(Container
the parent container in which to do the layout parent)Implements java. Lays out the specified container using this card layout. |
| public Dimension | maximumLayoutSize(Container
the component which needs to be laid out target)Implements java. Returns the maximum dimensions for this layout given the components in the specified target container. |
| public Dimension | Returns: the minimum dimensions required to lay out the subcomponents of the specified containerthe parent container in which to do the layout parent)Implements java. Calculates the minimum size for the specified panel. |
| public void | |
| public Dimension | Returns: the preferred dimensions to lay out the subcomponents of the specified containerthe parent container in which to do the layout parent)Implements java. Determines the preferred size of the container argument using this card layout. |
| public void | |
| private void | |
| public void | removeLayoutComponent(Component
the component to be removed. comp)Implements java. Removes the specified component from the layout. |
| public void | |
| public void | |
| public void | |
| pack-priv void | |
| public String | Returns: a string representation of this card layout.Overrides java. Returns a string representation of the state of this card layout. |
| private void | writeObject(ObjectOutputStream
the s)ObjectOutputStream to writeWrites serializable fields to stream. |
| currentCard | back to summary |
|---|---|
| pack-priv int currentCard | |
| hgap | back to summary |
|---|---|
| pack-priv int hgap | |
| serialPersistentFields | back to summary |
|---|---|
| private static final ObjectStreamField[] serialPersistentFields
| |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Use serialVersionUID from JDK 1.4 for interoperability. | |
| vector | back to summary |
|---|---|
| pack-priv Vector<CardLayout. | |
| vgap | back to summary |
|---|---|
| pack-priv int vgap | |
| CardLayout | back to summary |
|---|---|
| public CardLayout() Creates a new card layout with gaps of size zero. | |
| CardLayout | back to summary |
|---|---|
| public CardLayout(int hgap, int vgap) Creates a new card layout with the specified horizontal and vertical gaps. The horizontal gaps are placed at the left and right edges. The vertical gaps are placed at the top and bottom edges.
| |
| addLayoutComponent | back to summary |
|---|---|
| public void addLayoutComponent(Component comp, Object constraints) Implements java. Adds the specified component to this card layout's internal
table of names. The object specified by
| |
| addLayoutComponent | back to summary |
|---|---|
| public void addLayoutComponent(String name, Component comp) Implements java. Doc from java. Deprecated replaced by
If the layout manager uses a per-component string,
adds the component
| |
| checkLayout | back to summary |
|---|---|
| pack-priv void checkLayout(Container parent) Make sure that the Container really has a CardLayout installed. Otherwise havoc can ensue! | |
| first | back to summary |
|---|---|
| public void first(Container parent) Flips to the first card of the container.
| |
| getHgap | back to summary |
|---|---|
| public int getHgap() Gets the horizontal gap between components.
| |
| getLayoutAlignmentX | back to summary |
|---|---|
| public float getLayoutAlignmentX(Container parent) Implements java. Returns the alignment along the x axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc. | |
| getLayoutAlignmentY | back to summary |
|---|---|
| public float getLayoutAlignmentY(Container parent) Implements java. Returns the alignment along the y axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc. | |
| getVgap | back to summary |
|---|---|
| public int getVgap() Gets the vertical gap between components.
| |
| invalidateLayout | back to summary |
|---|---|
| public void invalidateLayout(Container target) Implements java. Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. | |
| last | back to summary |
|---|---|
| public void last(Container parent) Flips to the last card of the container.
| |
| layoutContainer | back to summary |
|---|---|
| public void layoutContainer(Container parent) Implements java. Lays out the specified container using this card layout.
Each component in the
| |
| maximumLayoutSize | back to summary |
|---|---|
| public Dimension maximumLayoutSize(Container target) Implements java. Returns the maximum dimensions for this layout given the components in the specified target container.
| |
| minimumLayoutSize | back to summary |
|---|---|
| public Dimension minimumLayoutSize(Container parent) Implements java. Calculates the minimum size for the specified panel.
| |
| next | back to summary |
|---|---|
| public void next(Container parent) Flips to the next card of the specified container. If the currently visible card is the last one, this method flips to the first card in the layout.
| |
| preferredLayoutSize | back to summary |
|---|---|
| public Dimension preferredLayoutSize(Container parent) Implements java. Determines the preferred size of the container argument using this card layout.
| |
| previous | back to summary |
|---|---|
| public void previous(Container parent) Flips to the previous card of the specified container. If the currently visible card is the first one, this method flips to the last card in the layout.
| |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException Reads serializable fields from stream.
| |
| removeLayoutComponent | back to summary |
|---|---|
| public void removeLayoutComponent(Component comp) Implements java. Removes the specified component from the layout. If the card was visible on top, the next card underneath it is shown.
| |
| setHgap | back to summary |
|---|---|
| public void setHgap(int hgap) Sets the horizontal gap between components.
| |
| setVgap | back to summary |
|---|---|
| public void setVgap(int vgap) Sets the vertical gap between components.
| |
| show | back to summary |
|---|---|
| public void show(Container parent, String name) Flips to the component that was added to this layout with the
specified
| |
| showDefaultComponent | back to summary |
|---|---|
| pack-priv void showDefaultComponent(Container parent) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string representation of the state of this card layout.
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream s) throws IOException Writes serializable fields to stream.
| |
| Modifier and Type | Field and Description |
|---|---|
| public Component | |
| public String | |
| private static final long | serialVersionUID
Use serialVersionUID from JDK 1.4 for interoperability. |
| Access | Constructor and Description |
|---|---|
| public |
| comp | back to summary |
|---|---|
| public Component comp | |
| name | back to summary |
|---|---|
| public String name | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Use serialVersionUID from JDK 1.4 for interoperability. | |
| Card | back to summary |
|---|---|
| public Card(String cardName, Component cardComponent) | |