Java AWT

Previous Chapter 19
java.awt Reference
Next
 

CardLayout

Name

CardLayout

[Graphic: Figure from the text]

Description

The CardLayout LayoutManager provides the means to manage multiple components, displaying one at a time. Components are displayed in the order in which they are added to the layout, or in an arbitrary order by using an assignable name.

Class Definition

public class java.awt.CardLayout
    extends java.lang.Object
    implements java.awt.LayoutManager2, java.io.Serializable {
  
  // Constructors
  public CardLayout();
  public CardLayout (int hgap, int vgap);
  
  // Instance Methods
  public void addLayoutComponent (Component comp, 
      Object constraints); (New)
  public void addLayoutComponent (String name, Component component); (Deprecated)
  public void first (Container parent);
  public int getHgap(); (New)
  public abstract float getLayoutAlignmentX(Container target); (New)
  public abstract float getLayoutAlignmentY(Container target); (New)
  public int getVgap(); (New)
  public abstract void invalidateLayout(Container target); (New)
  public void last (Container parent); 
  public void layoutContainer (Container target); 
  public abstract Dimension maximumLayoutSize(Container target); (New)
  public Dimension minimumLayoutSize (Container target); 
  public void next (Container parent); 
  public Dimension preferredLayoutSize (Container target); 
  public void previous (Container parent); 
  public void removeLayoutComponent (Component component); 
  public void setHgap (int hgap); (New)
  public void setVgap (int vgap); (New)
  public void show (Container parent, String name); 
  public String toString();
}

Constructors

CardLayout

public CardLayout()

Description

Constructs a CardLayout object.

public CardLayout (int hgap, int vgap)

Parameters

hgap

Horizontal space around left and right of container

vgap

Vertical space around top and bottom of container

Description

Constructs a CardLayout object with the values specified as the gaps around the container managed by this instance of CardLayout.

Instance Methods

addLayoutComponent

public void addLayoutComponent (Component comp, Object constraints) (New)

Parameters

comp

The component being added.

constraints

An object describing the constraints on this component.

Implements

LayoutManager2.addLayoutComponent()

Description

Adds the component comp to a container subject to the given constraints. This is a more generalized version of addLayoutComponent(String, Component). It corresponds to java.awt.Container's add(Component, Object). In practice, it is used the same in Java 1.1 as in Java 1.0.2, except with the parameters swapped:

Panel p = new Panel();
p.setLayoutManager(new CardLayout());
p.add(new Button("OK"), "Don Julio");

addLayoutComponent

public void addLayoutComponent (String name, Component component) (Deprecated)

Parameters

name

Name of the component to add.

component

The actual component being added.

Implements

LayoutManager.addLayoutComponent()

Description

Places component under the layout's management, assigning it the given name. This has been replaced in version 1.1 with the more general addLayoutComponent(Component, Object).

first

public void first (Container parent)

Parameters

parent

The container whose displayed component is changing.

Throws

IllegalArgumentException

If the LayoutManager of parent is not CardLayout.

Description

Sets the container to display the first component in parent.

getHgap

public int getHgap() (New)

Returns

The horizontal gap for this CardLayout instance.

getLayoutAlignmentX

public abstract float getLayoutAlignmentX (Container target) (New)

Parameters

target

The container to inspect.

Returns

The value .5 for all containers.

Description

This method returns the preferred alignment of the given container target. A return value of 0 is left aligned, .5 is centered, and 1 is right aligned.

getLayoutAlignmentY

public abstract float getLayoutAlignmentY (Container target) (New)

Parameters

target

The container to inspect.

Returns

The value .5 for all containers.

Description

This method returns the preferred alignment of the given container target. A return value of 0 is top aligned, .5 is centered, and 1 is bottom aligned.

getVgap

public int getVgap() (New)

Returns

The vertical gap for this CardLayout instance.

invalidateLayout

public abstract void invalidateLayout (Container target) (New)

Parameters

target

The container to invalidate.

Description

Does nothing.

last

public void last (Container parent)

Parameters

parent

The container whose displayed component is changing.

Throws

IllegalArgumentException

If the LayoutManager of parent is not CardLayout.

Description

Sets the container to display the final component in parent.

layoutContainer

public void layoutContainer (Container target)

Parameters

target

The container that needs to be redrawn.

Implements

LayoutManager.layoutContainer()

Description

Displays the currently selected component contained within target.

maximumLayoutSize

public abstract Dimension maximumLayoutSize (Container target) (New)

Parameters

target

The container to inspect.

Returns

A Dimension whose horizontal and vertical components are Integer.MAX_VALUE.

Description

For CardLayout, a maximal Dimension is always returned.

minimumLayoutSize

public Dimension minimumLayoutSize (Container target)

Parameters

target

The container whose size needs to be calculated.

Returns

Minimum Dimension of the container target.

Implements

LayoutManager.minimumLayoutSize()

Description

Calculates minimum size of the target container.

next

public void next (Container parent)

Parameters

parent

The container whose displayed component is changing.

Throws

IllegalArgumentException

If the LayoutManager of parent is not CardLayout.

Description

Sets the container to display the following component in the parent.

preferredLayoutSize

public Dimension preferredLayoutSize (Container target)

Parameters

target

The container whose size needs to be calculated.

Returns

Preferred Dimension of the container target.

Implements

LayoutManager.preferredLayoutSize()

Description

Calculates preferred size of the target container.

previous

public void previous (Container parent)

Parameters

parent

The container whose displayed component is changing.

Throws

IllegalArgumentException

If the LayoutManager of parent is not CardLayout.

Description

Sets the container to display the prior component in parent.

removeLayoutComponent

public void removeLayoutComponent (Component component)

Parameters

component

Component to stop tracking.

Implements

LayoutManager.removeLayoutComponent()

Description

Removes component from the layout manager's internal tables.

setHgap

public void setHgap (int hgap) (New)

Parameters

hgap

The horizontal gap value.

Description

Sets the horizontal gap for the left and right of the container.

setVgap

public void setVgap (int vgap) (New)

Parameters

vgap

The vertical gap value.

Description

Sets the vertical gap for the top and bottom of the container.

show

public void show (Container parent, String name)

Parameters

parent

The container whose displayed component is changing.

name

Name of component to display.

Throws

IllegalArgumentException

If LayoutManager of parent is not CardLayout.

Description

Sets the container to display the component name in parent.

toString

public String toString()

Returns

A string representation of the CardLayout object.

Overrides

Object.toString()

See Also

Component, Container, Dimension, LayoutManager, LayoutManager2, Object, String


Previous Home Next
Canvas Book Index Checkbox

Java in a Nutshell Java Language Reference Java AWT Java Fundamental Classes Exploring Java