| CardLayout |
|
typedict |
| |
A
CardLayout
is a layout manager that makes sure only one of the components
listed in container's
layout
array is visible at any time, and that the selected component
fills the container.
Components should be AWT or Swing components, however all layout managers
build a label appropriate for the container they are working on when they
find a
String
in the layout array where they expected a component.
Properties, like the font or foreground color, used by these short-hand
labels can not be directly specified, so they are inherited from the
container.
The fields in a
CardLayout
are:
| hgap |
A
double
that represents padding that is added to the left and right
of the selected component, in units of 72 dots per inch.
| | type |
A read-only
int
that is set to
CARDLAYOUT,
which is defined in
yoix.awt
and
yoix.swing.
| | vgap |
A
double
that represents padding that is added to the top and bottom
of the selected component, in units of 72 dots per inch.
|
Containers that can be managed by a
CardLayout
all declare an
Object
named
nextcard.
Storing a new value in
nextcard
picks the component that is displayed in the container
according to the following rules:
-
Any positive integer shows the next component,
or the first if the last component is showing.
-
Any negative integer shows the previous component,
or the last if the first component is showing.
-
POSITIVE_INFINITY
shows the last component.
-
NEGATIVE_INFINITY
shows the first component.
-
Any string shows the component in the layout
array that has the string as its
tag.
-
A component (e.g., a
Panel)
managed by the
CardLayout
means show that component.
No components use
CardLayout
as their default layout manager.
| |
| Example: |
The program,
import yoix.*.*;
JFrame f = {
CardLayout layoutmanager = {
int hgap = 36;
int vgap = 18;
};
Array layout = {
new JButton {
String tag = "first";
String text = "Next";
actionPerformed(e) {
root.nextcard = 1;
}
},
new JPanel {
Array layout = {
new JButton {
String text = "Next";
actionPerformed(e) {
root.nextcard = 1;
}
},
new JButton {
String text = "Quit";
actionPerformed(e) {
exit(0);
}
},
new JButton {
String text = "Previous";
actionPerformed(e) {
root.nextcard = -1;
}
},
};
},
new JButton {
String text = "First";
actionPerformed(e) {
root.nextcard = "first";
}
},
};
};
f.visible = TRUE;
puts three different components in a frame managed by a
CardLayout,
and shows how
nextcard
is used to show the different components.
| | |
| See Also: |
BorderLayout,
BoxLayout,
CustomLayout,
FlowLayout,
GridBagLayout,
GridLayout,
LayoutManager
|
|
Yoix is a registered trademark of AT&T Inc.
|