java.awt
Class CardLayout

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.awt.CardLayout
All Implemented Interfaces:
LayoutManager sample code for java.awt.LayoutManager definition code for java.awt.LayoutManager , LayoutManager2 sample code for java.awt.LayoutManager2 definition code for java.awt.LayoutManager2 , Serializable sample code for java.io.Serializable definition code for java.io.Serializable

public class CardLayout
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements LayoutManager2 sample code for java.awt.LayoutManager2 definition code for java.awt.LayoutManager2 , Serializable sample code for java.io.Serializable definition code for java.io.Serializable

A 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 addLayoutComponent(java.awt.Component, java.lang.Object) sample code for java.awt.CardLayout.addLayoutComponent(java.awt.Component, java.lang.Object) definition code for java.awt.CardLayout.addLayoutComponent(java.awt.Component, java.lang.Object) method can be used to associate a string identifier with a given card for fast random access.

Since:
JDK1.0
See Also:
Container sample code for java.awt.Container definition code for java.awt.Container , Serialized Form

Constructor Summary
CardLayout sample code for java.awt.CardLayout.CardLayout() definition code for java.awt.CardLayout.CardLayout() ()
          Creates a new card layout with gaps of size zero.
CardLayout sample code for java.awt.CardLayout.CardLayout(int, int) definition code for java.awt.CardLayout.CardLayout(int, int) (int hgap, int vgap)
          Creates a new card layout with the specified horizontal and vertical gaps.
 
Method Summary
 void addLayoutComponent sample code for java.awt.CardLayout.addLayoutComponent(java.awt.Component, java.lang.Object) definition code for java.awt.CardLayout.addLayoutComponent(java.awt.Component, java.lang.Object) (Component sample code for java.awt.Component definition code for java.awt.Component  comp, Object sample code for java.lang.Object definition code for java.lang.Object  constraints)
          Adds the specified component to this card layout's internal table of names.
 void addLayoutComponent sample code for java.awt.CardLayout.addLayoutComponent(java.lang.String, java.awt.Component) definition code for java.awt.CardLayout.addLayoutComponent(java.lang.String, java.awt.Component) (String sample code for java.lang.String definition code for java.lang.String  name, Component sample code for java.awt.Component definition code for java.awt.Component  comp)
          Deprecated. replaced by addLayoutComponent(Component, Object).
 void first sample code for java.awt.CardLayout.first(java.awt.Container) definition code for java.awt.CardLayout.first(java.awt.Container) (Container sample code for java.awt.Container definition code for java.awt.Container  parent)
          Flips to the first card of the container.
 int getHgap sample code for java.awt.CardLayout.getHgap() definition code for java.awt.CardLayout.getHgap() ()
          Gets the horizontal gap between components.
 float getLayoutAlignmentX sample code for java.awt.CardLayout.getLayoutAlignmentX(java.awt.Container) definition code for java.awt.CardLayout.getLayoutAlignmentX(java.awt.Container) (Container sample code for java.awt.Container definition code for java.awt.Container  parent)
          Returns the alignment along the x axis.
 float getLayoutAlignmentY sample code for java.awt.CardLayout.getLayoutAlignmentY(java.awt.Container) definition code for java.awt.CardLayout.getLayoutAlignmentY(java.awt.Container) (Container sample code for java.awt.Container definition code for java.awt.Container  parent)
          Returns the alignment along the y axis.
 int getVgap sample code for java.awt.CardLayout.getVgap() definition code for java.awt.CardLayout.getVgap() ()
          Gets the vertical gap between components.
 void invalidateLayout sample code for java.awt.CardLayout.invalidateLayout(java.awt.Container) definition code for java.awt.CardLayout.invalidateLayout(java.awt.Container) (Container sample code for java.awt.Container definition code for java.awt.Container  target)
          Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
 void last sample code for java.awt.CardLayout.last(java.awt.Container) definition code for java.awt.CardLayout.last(java.awt.Container) (Container sample code for java.awt.Container definition code for java.awt.Container  parent)
          Flips to the last card of the container.
 void layoutContainer sample code for java.awt.CardLayout.layoutContainer(java.awt.Container) definition code for java.awt.CardLayout.layoutContainer(java.awt.Container) (Container sample code for java.awt.Container definition code for java.awt.Container  parent)
          Lays out the specified container using this card layout.
 Dimension sample code for java.awt.Dimension definition code for java.awt.Dimension maximumLayoutSize sample code for java.awt.CardLayout.maximumLayoutSize(java.awt.Container) definition code for java.awt.CardLayout.maximumLayoutSize(java.awt.Container) (Container sample code for java.awt.Container definition code for java.awt.Container  target)
          Returns the maximum dimensions for this layout given the components in the specified target container.
 Dimension sample code for java.awt.Dimension definition code for java.awt.Dimension minimumLayoutSize sample code for java.awt.CardLayout.minimumLayoutSize(java.awt.Container) definition code for java.awt.CardLayout.minimumLayoutSize(java.awt.Container) (Container sample code for java.awt.Container definition code for java.awt.Container  parent)
          Calculates the minimum size for the specified panel.
 void next sample code for java.awt.CardLayout.next(java.awt.Container) definition code for java.awt.CardLayout.next(java.awt.Container) (Container sample code for java.awt.Container definition code for java.awt.Container  parent)
          Flips to the next card of the specified container.
 Dimension sample code for java.awt.Dimension definition code for java.awt.Dimension preferredLayoutSize sample code for java.awt.CardLayout.preferredLayoutSize(java.awt.Container) definition code for java.awt.CardLayout.preferredLayoutSize(java.awt.Container) (Container sample code for java.awt.Container definition code for java.awt.Container  parent)
          Determines the preferred size of the container argument using this card layout.
 void previous sample code for java.awt.CardLayout.previous(java.awt.Container) definition code for java.awt.CardLayout.previous(java.awt.Container) (Container sample code for java.awt.Container definition code for java.awt.Container  parent)
          Flips to the previous card of the specified container.
 void removeLayoutComponent sample code for java.awt.CardLayout.removeLayoutComponent(java.awt.Component) definition code for java.awt.CardLayout.removeLayoutComponent(java.awt.Component) (Component sample code for java.awt.Component definition code for java.awt.Component  comp)
          Removes the specified component from the layout.
 void setHgap sample code for java.awt.CardLayout.setHgap(int) definition code for java.awt.CardLayout.setHgap(int) (int hgap)
          Sets the horizontal gap between components.
 void setVgap sample code for java.awt.CardLayout.setVgap(int) definition code for java.awt.CardLayout.setVgap(int) (int vgap)
          Sets the vertical gap between components.
 void show sample code for java.awt.CardLayout.show(java.awt.Container, java.lang.String) definition code for java.awt.CardLayout.show(java.awt.Container, java.lang.String) (Container sample code for java.awt.Container definition code for java.awt.Container  parent, String sample code for java.lang.String definition code for java.lang.String  name)
          Flips to the component that was added to this layout with the specified name, using addLayoutComponent.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.awt.CardLayout.toString() definition code for java.awt.CardLayout.toString() ()
          Returns a string representation of the state of this card layout.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

CardLayout sample code for java.awt.CardLayout() definition code for java.awt.CardLayout()

public CardLayout()
Creates a new card layout with gaps of size zero.


CardLayout sample code for java.awt.CardLayout(int, int) definition code for java.awt.CardLayout(int, int)

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.

Parameters:
hgap - the horizontal gap.
vgap - the vertical gap.
Method Detail

getHgap sample code for java.awt.CardLayout.getHgap() definition code for java.awt.CardLayout.getHgap()

public int getHgap()
Gets the horizontal gap between components.

Returns:
the horizontal gap between components.
Since:
JDK1.1
See Also:
setHgap(int) sample code for java.awt.CardLayout.setHgap(int) definition code for java.awt.CardLayout.setHgap(int) , getVgap() sample code for java.awt.CardLayout.getVgap() definition code for java.awt.CardLayout.getVgap()

setHgap sample code for java.awt.CardLayout.setHgap(int) definition code for java.awt.CardLayout.setHgap(int)

public void setHgap(int hgap)
Sets the horizontal gap between components.

Parameters:
hgap - the horizontal gap between components.
Since:
JDK1.1
See Also:
getHgap() sample code for java.awt.CardLayout.getHgap() definition code for java.awt.CardLayout.getHgap() , setVgap(int) sample code for java.awt.CardLayout.setVgap(int) definition code for java.awt.CardLayout.setVgap(int)

getVgap sample code for java.awt.CardLayout.getVgap() definition code for java.awt.CardLayout.getVgap()

public int getVgap()
Gets the vertical gap between components.

Returns:
the vertical gap between components.
See Also:
setVgap(int) sample code for java.awt.CardLayout.setVgap(int) definition code for java.awt.CardLayout.setVgap(int) , getHgap() sample code for java.awt.CardLayout.getHgap() definition code for java.awt.CardLayout.getHgap()

setVgap sample code for java.awt.CardLayout.setVgap(int) definition code for java.awt.CardLayout.setVgap(int)

public void setVgap(int vgap)
Sets the vertical gap between components.

Parameters:
vgap - the vertical gap between components.
Since:
JDK1.1
See Also:
getVgap() sample code for java.awt.CardLayout.getVgap() definition code for java.awt.CardLayout.getVgap() , setHgap(int) sample code for java.awt.CardLayout.setHgap(int) definition code for java.awt.CardLayout.setHgap(int)

addLayoutComponent sample code for java.awt.CardLayout.addLayoutComponent(java.awt.Component, java.lang.Object) definition code for java.awt.CardLayout.addLayoutComponent(java.awt.Component, java.lang.Object)

public void addLayoutComponent(Component sample code for java.awt.Component definition code for java.awt.Component  comp,
                               Object sample code for java.lang.Object definition code for java.lang.Object  constraints)
Adds the specified component to this card layout's internal table of names. The object specified by constraints must be a string. The card layout stores this string as a key-value pair that can be used for random access to a particular card. By calling the show method, an application can display the component with the specified name.

Specified by:
addLayoutComponent sample code for java.awt.LayoutManager2.addLayoutComponent(java.awt.Component, java.lang.Object) definition code for java.awt.LayoutManager2.addLayoutComponent(java.awt.Component, java.lang.Object) in interface LayoutManager2 sample code for java.awt.LayoutManager2 definition code for java.awt.LayoutManager2
Parameters:
comp - the component to be added.
constraints - a tag that identifies a particular card in the layout.
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if the constraint is not a string.
See Also:
show(java.awt.Container, java.lang.String) sample code for java.awt.CardLayout.show(java.awt.Container, java.lang.String) definition code for java.awt.CardLayout.show(java.awt.Container, java.lang.String)

addLayoutComponent sample code for java.awt.CardLayout.addLayoutComponent(java.lang.String, java.awt.Component) definition code for java.awt.CardLayout.addLayoutComponent(java.lang.String, java.awt.Component)

@Deprecated
public void addLayoutComponent(String sample code for java.lang.String definition code for java.lang.String  name,
                                          Component sample code for java.awt.Component definition code for java.awt.Component  comp)
Deprecated. replaced by addLayoutComponent(Component, Object).

Description copied from interface: LayoutManager sample code for java.awt.LayoutManager.addLayoutComponent(java.lang.String, java.awt.Component) definition code for java.awt.LayoutManager.addLayoutComponent(java.lang.String, java.awt.Component)
If the layout manager uses a per-component string, adds the component comp to the layout, associating it with the string specified by name.

Specified by:
addLayoutComponent sample code for java.awt.LayoutManager.addLayoutComponent(java.lang.String, java.awt.Component) definition code for java.awt.LayoutManager.addLayoutComponent(java.lang.String, java.awt.Component) in interface LayoutManager sample code for java.awt.LayoutManager definition code for java.awt.LayoutManager
Parameters:
name - the string to be associated with the component
comp - the component to be added

removeLayoutComponent sample code for java.awt.CardLayout.removeLayoutComponent(java.awt.Component) definition code for java.awt.CardLayout.removeLayoutComponent(java.awt.Component)

public void removeLayoutComponent(Component sample code for java.awt.Component definition code for java.awt.Component  comp)
Removes the specified component from the layout.

Specified by:
removeLayoutComponent sample code for java.awt.LayoutManager.removeLayoutComponent(java.awt.Component) definition code for java.awt.LayoutManager.removeLayoutComponent(java.awt.Component) in interface LayoutManager sample code for java.awt.LayoutManager definition code for java.awt.LayoutManager
Parameters:
comp - the component to be removed.
See Also:
Container.remove(java.awt.Component) sample code for java.awt.Container.remove(java.awt.Component) definition code for java.awt.Container.remove(java.awt.Component) , Container.removeAll() sample code for java.awt.Container.removeAll() definition code for java.awt.Container.removeAll()

preferredLayoutSize sample code for java.awt.CardLayout.preferredLayoutSize(java.awt.Container) definition code for java.awt.CardLayout.preferredLayoutSize(java.awt.Container)

public Dimension sample code for java.awt.Dimension definition code for java.awt.Dimension  preferredLayoutSize(Container sample code for java.awt.Container definition code for java.awt.Container  parent)
Determines the preferred size of the container argument using this card layout.

Specified by:
preferredLayoutSize sample code for java.awt.LayoutManager.preferredLayoutSize(java.awt.Container) definition code for java.awt.LayoutManager.preferredLayoutSize(java.awt.Container) in interface LayoutManager sample code for java.awt.LayoutManager definition code for java.awt.LayoutManager
Parameters:
parent - the parent container in which to do the layout
Returns:
the preferred dimensions to lay out the subcomponents of the specified container
See Also:
Container.getPreferredSize() sample code for java.awt.Container.getPreferredSize() definition code for java.awt.Container.getPreferredSize() , minimumLayoutSize(java.awt.Container) sample code for java.awt.CardLayout.minimumLayoutSize(java.awt.Container) definition code for java.awt.CardLayout.minimumLayoutSize(java.awt.Container)

minimumLayoutSize sample code for java.awt.CardLayout.minimumLayoutSize(java.awt.Container) definition code for java.awt.CardLayout.minimumLayoutSize(java.awt.Container)

public Dimension sample code for java.awt.Dimension definition code for java.awt.Dimension  minimumLayoutSize(Container sample code for java.awt.Container definition code for java.awt.Container  parent)
Calculates the minimum size for the specified panel.

Specified by:
minimumLayoutSize sample code for java.awt.LayoutManager.minimumLayoutSize(java.awt.Container) definition code for java.awt.LayoutManager.minimumLayoutSize(java.awt.Container) in interface LayoutManager sample code for java.awt.LayoutManager definition code for java.awt.LayoutManager
Parameters:
parent - the parent container in which to do the layout
Returns:
the minimum dimensions required to lay out the subcomponents of the specified container
See Also:
Container.doLayout() sample code for java.awt.Container.doLayout() definition code for java.awt.Container.doLayout() , preferredLayoutSize(java.awt.Container) sample code for java.awt.CardLayout.preferredLayoutSize(java.awt.Container) definition code for java.awt.CardLayout.preferredLayoutSize(java.awt.Container)

maximumLayoutSize sample code for java.awt.CardLayout.maximumLayoutSize(java.awt.Container) definition code for java.awt.CardLayout.maximumLayoutSize(java.awt.Container)

public Dimension sample code for java.awt.Dimension definition code for java.awt.Dimension  maximumLayoutSize(Container sample code for java.awt.Container definition code for java.awt.Container  target)
Returns the maximum dimensions for this layout given the components in the specified target container.

Specified by:
maximumLayoutSize sample code for java.awt.LayoutManager2.maximumLayoutSize(java.awt.Container) definition code for java.awt.LayoutManager2.maximumLayoutSize(java.awt.Container) in interface LayoutManager2 sample code for java.awt.LayoutManager2 definition code for java.awt.LayoutManager2
Parameters:
target - the component which needs to be laid out
See Also:
Container sample code for java.awt.Container definition code for java.awt.Container , minimumLayoutSize(java.awt.Container) sample code for java.awt.CardLayout.minimumLayoutSize(java.awt.Container) definition code for java.awt.CardLayout.minimumLayoutSize(java.awt.Container) , preferredLayoutSize(java.awt.Container) sample code for java.awt.CardLayout.preferredLayoutSize(java.awt.Container) definition code for java.awt.CardLayout.preferredLayoutSize(java.awt.Container)

getLayoutAlignmentX sample code for java.awt.CardLayout.getLayoutAlignmentX(java.awt.Container) definition code for java.awt.CardLayout.getLayoutAlignmentX(java.awt.Container)

public float getLayoutAlignmentX(Container sample code for java.awt.Container definition code for java.awt.Container  parent)
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.

Specified by:
getLayoutAlignmentX sample code for java.awt.LayoutManager2.getLayoutAlignmentX(java.awt.Container) definition code for java.awt.LayoutManager2.getLayoutAlignmentX(java.awt.Container) in interface LayoutManager2 sample code for java.awt.LayoutManager2 definition code for java.awt.LayoutManager2

getLayoutAlignmentY sample code for java.awt.CardLayout.getLayoutAlignmentY(java.awt.Container) definition code for java.awt.CardLayout.getLayoutAlignmentY(java.awt.Container)

public float getLayoutAlignmentY(Container sample code for java.awt.Container definition code for java.awt.Container  parent)
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.

Specified by:
getLayoutAlignmentY sample code for java.awt.LayoutManager2.getLayoutAlignmentY(java.awt.Container) definition code for java.awt.LayoutManager2.getLayoutAlignmentY(java.awt.Container) in interface LayoutManager2 sample code for java.awt.LayoutManager2 definition code for java.awt.LayoutManager2

invalidateLayout sample code for java.awt.CardLayout.invalidateLayout(java.awt.Container) definition code for java.awt.CardLayout.invalidateLayout(java.awt.Container)

public void invalidateLayout(Container sample code for java.awt.Container definition code for java.awt.Container  target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.

Specified by:
invalidateLayout sample code for java.awt.LayoutManager2.invalidateLayout(java.awt.Container) definition code for java.awt.LayoutManager2.invalidateLayout(java.awt.Container) in interface LayoutManager2 sample code for java.awt.LayoutManager2 definition code for java.awt.LayoutManager2

layoutContainer sample code for java.awt.CardLayout.layoutContainer(java.awt.Container) definition code for java.awt.CardLayout.layoutContainer(java.awt.Container)

public void layoutContainer(Container sample code for java.awt.Container definition code for java.awt.Container  parent)
Lays out the specified container using this card layout.

Each component in the parent container is reshaped to be the size of the container, minus space for surrounding insets, horizontal gaps, and vertical gaps.

Specified by:
layoutContainer sample code for java.awt.LayoutManager.layoutContainer(java.awt.Container) definition code for java.awt.LayoutManager.layoutContainer(java.awt.Container) in interface LayoutManager sample code for java.awt.LayoutManager definition code for java.awt.LayoutManager
Parameters:
parent - the parent container in which to do the layout
See Also:
Container.doLayout() sample code for java.awt.Container.doLayout() definition code for java.awt.Container.doLayout()

first sample code for java.awt.CardLayout.first(java.awt.Container) definition code for java.awt.CardLayout.first(java.awt.Container)

public void first(Container sample code for java.awt.Container definition code for java.awt.Container  parent)
Flips to the first card of the container.

Parameters:
parent - the parent container in which to do the layout
See Also:
last(java.awt.Container) sample code for java.awt.CardLayout.last(java.awt.Container) definition code for java.awt.CardLayout.last(java.awt.Container)

next sample code for java.awt.CardLayout.next(java.awt.Container) definition code for java.awt.CardLayout.next(java.awt.Container)

public void next(Container sample code for java.awt.Container definition code for java.awt.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.

Parameters:
parent - the parent container in which to do the layout
See Also:
previous(java.awt.Container) sample code for java.awt.CardLayout.previous(java.awt.Container) definition code for java.awt.CardLayout.previous(java.awt.Container)

previous sample code for java.awt.CardLayout.previous(java.awt.Container) definition code for java.awt.CardLayout.previous(java.awt.Container)

public void previous(Container sample code for java.awt.Container definition code for java.awt.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.

Parameters:
parent - the parent container in which to do the layout
See Also:
next(java.awt.Container) sample code for java.awt.CardLayout.next(java.awt.Container) definition code for java.awt.CardLayout.next(java.awt.Container)

last sample code for java.awt.CardLayout.last(java.awt.Container) definition code for java.awt.CardLayout.last(java.awt.Container)

public void last(Container sample code for java.awt.Container definition code for java.awt.Container  parent)
Flips to the last card of the container.

Parameters:
parent - the parent container in which to do the layout
See Also:
first(java.awt.Container) sample code for java.awt.CardLayout.first(java.awt.Container) definition code for java.awt.CardLayout.first(java.awt.Container)

show sample code for java.awt.CardLayout.show(java.awt.Container, java.lang.String) definition code for java.awt.CardLayout.show(java.awt.Container, java.lang.String)

public void show(Container sample code for java.awt.Container definition code for java.awt.Container  parent,
                 String sample code for java.lang.String definition code for java.lang.String  name)
Flips to the component that was added to this layout with the specified name, using addLayoutComponent. If no such component exists, then nothing happens.

Parameters:
parent - the parent container in which to do the layout
name - the component name
See Also:
addLayoutComponent(java.awt.Component, java.lang.Object) sample code for java.awt.CardLayout.addLayoutComponent(java.awt.Component, java.lang.Object) definition code for java.awt.CardLayout.addLayoutComponent(java.awt.Component, java.lang.Object)

toString sample code for java.awt.CardLayout.toString() definition code for java.awt.CardLayout.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Returns a string representation of the state of this card layout.

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
a string representation of this card layout.