A LayoutSpec specifies how an item is to be laid out in a
TopLevel or other graphical container (here, we'll refer to such things
collectively as containers). It corresponds to
the class GridBagConstraints
from the usual Java AWT
framework. That is, the container is considered to be divided
into rows of equal numbers of grid cells. The cells in any given
column have the same width and those in any given row have the same height.
The system is responsible for figuring out what these widths and heights
should be, based on the sizes of the components and the layout parameters
supplied by this class. For any component that you add to a container,
you supply a LayoutSpec that indicates what grid cells the component is
to occupy, any
padding added to the component, and the insets—the
space left between the
component and the sides of its grid cells.
You supply parameters to a
LayoutSpec are specified as arrays
of values: NAME1, VALUE1, NAME2, VALUE2, where the NAMEs denote
particular parameters, and the VALUEs give their values.
Unmentioned parameters have default values. Here are the possible
NAMES and the expected values:
Parameter name | Parameter type |
Description |
width | Integer |
The number of grid cells (>=1) occupied by this
component horizontally.
May also have the string value "rest" or "remainder", which
indicates that it occupies all remaining grid cells in its
row(s), thus completing the row(s). |
height | Integer |
The number of grid cells occupied by this component vertically.
May also have the string value "rest" or "remainder", which
indicates that it occupies all remaining grid cells in its
columns(s), thus completing the column(s). |
By default, a component gets placed in the rightmost
grid cell of the topmost incomplete row. By specifying
x and y grid coordinates (top, leftmost cell is x=0,
y=0), you can place components at arbitrary places. |
x | Integer |
The column number of the upper-left corner of the component,
where column 0 is leftmost. |
y | Integer |
The row number of the upper-left corner of the component,
where row 0 is topmost. |
If a component's preferred size does not fill the area
provided in the grid (which is determined by the sizes of other
components in the grid and the size of the entire container),
the component may be expanded to fill the area, or placed at a
particular position within the area, as determined by the
next two parameters. |
anchor | String |
If the component does not fill the grid cells it occupies, this
parameter indicates where it should go. Possible values are
"center" (default), "north" (top), "south", "west", "east",
"southwest", "southeast", "northwest", and "northeast". |
fill | String |
If the component does not fill the grid cells it occupies, this
parameter indicates how it should be expanded. The default
is no expansion. Possible values are
"horizontal" (or "horiz"), "vertical" (or "vert"), and
"both", indicating whether the component is to expand in the
horizontal direction, vertical direction, or both. |
The following parameters specify for minimal space
between a component and the edges of its grid cell. |
ileft | Integer |
Space (in pixels) to be left between component's left side and
its grid cell. |
iright | Integer |
Space (in pixels) to be left between component's right side and
its grid cell. |
itop | Integer |
Space (in pixels) to be left between component's top side and
its grid cell. |
ibottom | Integer |
Space (in pixels) to be left between component's bottom side and
its grid cell. |
The following parameters specify the relative weights
given to components for distribution of extra (or reduced)
space resulting from resizing. When set to 0, the component
requests no extra space on being resized. Default is 1.0. |
weightx | Double |
Weight for receiving more (less) space from resizing in the
horizontal direction. |
weighty | Double |
Weight for receiving more (less) space from resizing in the
horizontal direction. |