This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


java.awt
class CardLayout

java.lang.Object extended by java.awt.CardLayout
All Implemented Interfaces:
LayoutManager2, Serializable

Most common way to construct:

CardLayout cardLayout = new CardLayout();

Based on 95 examples


public class CardLayout
extends Object
implements LayoutManager2, 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 {@link CardLayout#addLayoutComponent} method can be used to associate a string identifier with a given card for fast random access.


Constructor Summary

          Creates a new card layout with gaps of size zero.
CardLayout(int hgap, int vgap)

          Creates a new card layout with the specified horizontal and vertical gaps.
 
Method Summary
 void
addLayoutComponent(Component comp, Object constraints)

          Adds the specified component to this card layout's internal table of names.
 void

          
 void
first(Container parent)

          Flips to the first card of the container.
 int

          Gets the horizontal gap between components.
 float

          Returns the alignment along the x axis.
 float

          Returns the alignment along the y axis.
 int

          Gets the vertical gap between components.
 void

          Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
 void
last(Container parent)

          Flips to the last card of the container.
 void

          Lays out the specified container using this card layout.
 Dimension

          Returns the maximum dimensions for this layout given the components in the specified target container.
 Dimension

          Calculates the minimum size for the specified panel.
 void
next(Container parent)

          Flips to the next card of the specified container.
 Dimension

          Determines the preferred size of the container argument using this card layout.
 void

          Flips to the previous card of the specified container.
 void

          Removes the specified component from the layout.
 void
setHgap(int hgap)

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

          Sets the vertical gap between components.
 void
show(Container parent, String name)

          Flips to the component that was added to this layout with the specified name, using addLayoutComponent.
 String

          Returns a string representation of the state of this card layout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CardLayout

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


CardLayout

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

addLayoutComponent

public void addLayoutComponent(Component comp,
                               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.

Parameters:
comp - the component to be added.
constraints - a tag that identifies a particular card in the layout.

addLayoutComponent

public void addLayoutComponent(String name,
                               Component comp)
Parameters:
name
comp

first

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

Parameters:
parent - the parent container in which to do the layout

getHgap

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

Returns:
the horizontal gap between components.

getLayoutAlignmentX

public float getLayoutAlignmentX(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.

Parameters:
parent

getLayoutAlignmentY

public float getLayoutAlignmentY(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.

Parameters:
parent

getVgap

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

Returns:
the vertical gap between components.

invalidateLayout

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

Parameters:
target

last

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

Parameters:
parent - the parent container in which to do the layout

layoutContainer

public void layoutContainer(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.

Parameters:
parent - the parent container in which to do the layout

maximumLayoutSize

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

Parameters:
target - the component which needs to be laid out

minimumLayoutSize

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

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

next

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.

Parameters:
parent - the parent container in which to do the layout

preferredLayoutSize

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

Parameters:
parent - the parent container in which to do the layout
Returns:
the preferred dimensions to lay out the subcomponents of the specified container

previous

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.

Parameters:
parent - the parent container in which to do the layout

removeLayoutComponent

public void removeLayoutComponent(Component comp)
Removes the specified component from the layout. If the card was visible on top, the next card underneath it is shown.

Parameters:
comp - the component to be removed.

setHgap

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

Parameters:
hgap - the horizontal gap between components.

setVgap

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

Parameters:
vgap - the vertical gap between components.

show

public void show(Container parent,
                 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

toString

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

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


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.