java.awt
Class CardLayout

java.lang.Object
  |
  +--java.awt.CardLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2, Serializable

public class CardLayout
extends Object
implements LayoutManager2, Serializable

Safe: 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) method can be used to associate a string identifier with a given card for fast random access.

Since:
JDK1.0
Version:
1.37 01/19/03
Author:
Arthur van Hoff
See Also:
java.awt.Container, Serialized Form

Field Summary
(package private)  int currentCard
           
(package private)  int hgap
           
private static ObjectStreamField[] serialPersistentFields
           
private static long serialVersionUID
           
(package private)  Vector vector
           
(package private)  int vgap
           
 
Constructor Summary
CardLayout()
          Enabled: Creates a new card layout with gaps of size zero.
CardLayout(int hgap, int vgap)
          Enabled: Creates a new card layout with the specified horizontal and vertical gaps.
 
Method Summary
 void addLayoutComponent(Component comp, Object constraints)
          Enabled: Adds the specified component to this card layout's internal table of names.
 void addLayoutComponent(String name, Component comp)
          Enabled: @deprecated replaced by addLayoutComponent(Component, Object).
(package private)  void checkLayout(Container parent)
          Make sure that the Container really has a CardLayout installed.
 void first(Container parent)
          Enabled: Flips to the first card of the container.
 int getHgap()
          Enabled: Gets the horizontal gap between components.
 float getLayoutAlignmentX(Container parent)
          Enabled: Returns the alignment along the x axis.
 float getLayoutAlignmentY(Container parent)
          Enabled: Returns the alignment along the y axis.
 int getVgap()
          Enabled: Gets the vertical gap between components.
 void invalidateLayout(Container target)
          Enabled: Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
 void last(Container parent)
          Enabled: Flips to the last card of the container.
 void layoutContainer(Container parent)
          Enabled: Lays out the specified container using this card layout.
 Dimension maximumLayoutSize(Container target)
          Enabled: Returns the maximum dimensions for this layout given the components in the specified target container.
 Dimension minimumLayoutSize(Container parent)
          Enabled: Calculates the minimum size for the specified panel.
 void next(Container parent)
          Enabled: Flips to the next card of the specified container.
 Dimension preferredLayoutSize(Container parent)
          Enabled: Determines the preferred size of the container argument using this card layout.
 void previous(Container parent)
          Enabled: Flips to the previous card of the specified container.
private  void readObject(ObjectInputStream s)
          Reads serializable fields from stream.
 void removeLayoutComponent(Component comp)
          Enabled: Removes the specified component from the layout.
 void setHgap(int hgap)
          Enabled: Sets the horizontal gap between components.
 void setVgap(int vgap)
          Enabled: Sets the vertical gap between components.
(package private)  void show(Container parent, int newIndex)
           
 void show(Container parent, String name)
          Enabled: Flips to the component that was added to this layout with the specified name, using addLayoutComponent.
 String toString()
          Suppressed: Returns a string representation of the state of this card layout.
private  void writeObject(ObjectOutputStream s)
          Writes serializable fields to stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID

vector

Vector vector

currentCard

int currentCard

hgap

int hgap

vgap

int vgap

serialPersistentFields

private static final ObjectStreamField[] serialPersistentFields
Constructor Detail

CardLayout

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


CardLayout

public CardLayout(int hgap,
                  int vgap)
Enabled: 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

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

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

setHgap

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

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

getVgap

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

Returns:
the vertical gap between components.
See Also:
java.awt.CardLayout#setVgap(int), java.awt.CardLayout#getHgap()

setVgap

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

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

addLayoutComponent

public void addLayoutComponent(Component comp,
                               Object constraints)
Enabled: 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 in interface LayoutManager2
Parameters:
comp - the component to be added.
constraints - a tag that identifies a particular card in the layout.
See Also:
java.awt.CardLayout#show(java.awt.Container, java.lang.String)

addLayoutComponent

public void addLayoutComponent(String name,
                               Component comp)
Enabled: @deprecated replaced by addLayoutComponent(Component, Object).

Specified by:
addLayoutComponent in interface LayoutManager
Parameters:
name - the string to be associated with the component
comp - the component to be added

removeLayoutComponent

public void removeLayoutComponent(Component comp)
Enabled: Removes the specified component from the layout.

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

preferredLayoutSize

public Dimension preferredLayoutSize(Container parent)
Enabled: Determines the preferred size of the container argument using this card layout.

Specified by:
preferredLayoutSize in interface LayoutManager
Parameters:
parent - the name of the parent container.
Returns:
the preferred dimensions to lay out the subcomponents of the specified container.
See Also:
java.awt.Container#getPreferredSize, java.awt.CardLayout#minimumLayoutSize

minimumLayoutSize

public Dimension minimumLayoutSize(Container parent)
Enabled: Calculates the minimum size for the specified panel.

Specified by:
minimumLayoutSize in interface LayoutManager
Parameters:
parent - the name of 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:
java.awt.Container#doLayout, java.awt.CardLayout#preferredLayoutSize

maximumLayoutSize

public Dimension maximumLayoutSize(Container target)
Enabled: Returns the maximum dimensions for this layout given the components in the specified target container.

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

getLayoutAlignmentX

public float getLayoutAlignmentX(Container parent)
Enabled: 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 in interface LayoutManager2

getLayoutAlignmentY

public float getLayoutAlignmentY(Container parent)
Enabled: 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 in interface LayoutManager2

invalidateLayout

public void invalidateLayout(Container target)
Enabled: Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.

Specified by:
invalidateLayout in interface LayoutManager2

layoutContainer

public void layoutContainer(Container parent)
Enabled: 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 in interface LayoutManager
Parameters:
parent - the name of the parent container in which to do the layout.
See Also:
java.awt.Container#doLayout

checkLayout

void checkLayout(Container parent)
Make sure that the Container really has a CardLayout installed. Otherwise havoc can ensue!


first

public void first(Container parent)
Enabled: Flips to the first card of the container.

Parameters:
parent - the name of the parent container in which to do the layout.
See Also:
java.awt.CardLayout#last

next

public void next(Container parent)
Enabled: 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 name of the parent container in which to do the layout.
See Also:
java.awt.CardLayout#previous

previous

public void previous(Container parent)
Enabled: 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 name of the parent container in which to do the layout.
See Also:
java.awt.CardLayout#next

last

public void last(Container parent)
Enabled: Flips to the last card of the container.

Parameters:
parent - the name of the parent container in which to do the layout.
See Also:
java.awt.CardLayout#first

show

public void show(Container parent,
                 String name)
Enabled: 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 name of the parent container in which to do the layout.
name - the component name.
See Also:
java.awt.CardLayout#addLayoutComponent(java.awt.Component, java.lang.Object)

show

void show(Container parent,
          int newIndex)

toString

public String toString()
Suppressed: Returns a string representation of the state of this card layout.

Overrides:
toString in class Object
Returns:
a string representation of this card layout.

readObject

private void readObject(ObjectInputStream s)
                 throws ClassNotFoundException,
                        IOException
Reads serializable fields from stream.

ClassNotFoundException
IOException

writeObject

private void writeObject(ObjectOutputStream s)
                  throws IOException
Writes serializable fields to stream.

IOException


comments?