Java Reference
In-Depth Information
The top-left cell in a layout is at position (0, 0). You specify the position of a component by defining
where the top-left cell that it occupies is, relative to either the grid origin, or relative to the last
component that was added to the container. You specify the position of the top-left cell that a
component occupies in the grid by setting values of type int for the gridx and gridy members of the
GridBagConstraints object. The default value for gridx is GridBagConstraints.RELATIVE -
a constant that places the top-left grid position for the component in the column immediately to the
right of the previous component. The same value is the default for gridy , which places the next
component immediately below the previous one.
You specify the number of cells occupied by a component horizontally and vertically by setting values
for the gridwidth and gridheight instance variables for the GridBagConstraints object. The
default value for both of these is 1 . There are two constants you can use as values for these variables.
With a value of GridBagConstraints.REMAINDER , the component will be the last one in the row or
column. If you specify the value as GridBagConstraints.RELATIVE , the component will be the
penultimate one in the row or column.
If the preferred size of the component is less than the display area, you can control how the size of the
component is adjusted to fit the display area by setting the fill and insets instance variables for the
GridBagConstraints object.
Variable
Description
fill
The value for this variable is of type int , and it determines how the size of the
component is adjusted in relation to the array of cells it occupies. The default
value of GridBagConstraints.NONE means that the component is not
resized.
A value of GridBagConstraints.HORIZONTAL adjusts the width of the
component to fill the display area.
A value of GridBagConstraints.VERTICAL adjusts the height of the
component to fill the display area.
A value of GridBagConstraints.BOTH adjusts the height and the width to
completely fill the display area.
insets
This variable stores a reference to an object of type Insets . An Insets
object defines the space allowed between the edges of the components and
boundaries of the display area it occupies. Four parameter values to the class
constructor define the top, left-side, bottom and right-side padding from the
edges of the component. The default value is Insets(0, 0, 0, 0) .
If you don't intend to expand a component to fill its display area, you may still want to enlarge the
component from its minimum size. You can adjust the dimensions of the component by setting the
following GridBagConstraints instance variables:
Search WWH ::




Custom Search