| BoxLayout |
|
typedict |
| |
|
A
BoxLayout
is a simple layout manager that arranges components in a container in a
single horizontal row or vertical column in the same order that they
appear in the container's
layout
array.
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.
BoxLayout
also accepts numbers or
Dimensions
in the layout array and treats them as requests to create rigid or expandable
components that are added to the container at the point that they appear in the
layout array.
A positive number is interpreted as the length, in units of 72 dots
per inch, of a rigid component (a strut) that extends in the direction
specified by the
orientation
of the
BoxLayout,
a negtive number specifies the length of a strut that extends in the
direction perpendicular to
orientation,
and zero means create an expandable component (glue) that can stretch
in the direction specified by
orientation.
The fields in a
BoxLayout
are:
| orientation |
An
int
that determines whether the components in the container are arranged
in a row or column.
The value should be
HORIZONTAL
or
VERTICAL
which are defined in
yoix.awt
and
yoix.swing.
| | type |
A read-only
int
that is set to
BOXLAYOUT,
which is defined in
yoix.awt
and
yoix.swing.
|
No components use
BoxLayout
as their default layout manager.
| |
| Example: |
The program,
import yoix.*.*;
JFrame f = {
Dimension size = NULL;
BoxLayout layoutmanager = {
int orientation = VERTICAL;
};
Array layout = {
72.0/16, // 1/16 inch strut
new JButton {
String text = "Top";
},
72.0, // 1 inch strut
new JPanel {
BoxLayout layoutmanager = {
int orientation = HORIZONTAL;
};
Array layout = {
72.0/4, // 1/4 inch strut
new JButton {
String text = "Left";
},
0, // glue
new JButton {
String text = "Quit";
actionPerformed(ActionEvent e) {
exit(0);
}
},
0, // glue
new JButton {
String text = "Right";
},
72.0/4, // 1/4 inch strut
};
},
2*72, // 2 inch strut
new JPanel {
Array layout = {
new JButton {
String text = "Bottom";
},
};
},
72.0/16, // 1/16 inch strut
};
};
f.visible = TRUE;
places several buttons in a frame using one horizontal and one vertical
BoxLayout.
Do you understand why the buttons labeled "Top" and "Bottom" don't line up?
| | |
| See Also: |
BorderLayout,
CardLayout,
CustomLayout,
FlowLayout,
GridBagLayout,
GridLayout,
LayoutManager
|
|
Yoix is a registered trademark of AT&T Intellectual Property.
|