Using the GridBag Customizer
See Also
The GridBag customizer enables you to visually adjust the placement and constraints
of components in a GridBagLayout. It includes a property sheet for GridBag
constraints, buttons for adjusting the constraints, and a rough depiction of
the layout of the components. The GUI Builder more closely reflects how the
components will look at runtime.
To use the GridBag customizer:
- Add the components you require to your form and ensure the GridBagLayout
is set for it.
- To open the customizer, right-click the GridBagLayout node in the Inspector
window and choose Customize from the contextual menu.
- Drag the components in the right pane to reposition them as desired. As
you drag a component, its Grid X and Grid Y properties change to reflect
its new position.
- Once the approximate layout of the components has been established,
select a component and adjust its constraints as desired
in the left pane. Note that you can either enter the values directly or
use the provided buttons to adjust the component's constraints.
- Once you are satisfied with the layout, click Close to exit the customizer.
The IDE updates the edited components to reflect there new positions.
You can adjust the following constraints:
- Grid X and Grid Y. Fine-tune the component's horizontal
and vertical position if necessary by setting its X and Y grid positions.
- Grid Width and Grid Height. Set Grid Width and Grid Height
to specify how many grid positions are allocated for the component in each
direction. Specify either:
- An integer value - the number of cells the component uses, (not the
number of pixels)
- Remainder - to make the component the last one in its row or column,
using all remaining horizontal or vertical space
- Relative - to specify that the component be the next to last one in
its row or column
You can also adjust Grid Width and Height using the Grid Size buttons.
Click the rightmost button with yellow shading to set the value to Remainder.
- Fill. The Fill constraint enables you to choose whether
the component uses all of the vertical or horizontal space (or both) that
is allocated to it. Any space allocated to a component that the component
does not fill is marked with blue in the right pane.
- Internal Padding X and Y. The internal padding settings
enable you to increase the horizontal and vertical dimensions of the component.
You can adjust these by directly entering numbers for the properties or
by using the I-Padding buttons.
- Anchor. The Anchor constraint enables you to place the component
in one of nine positions within the space allocated to it (Center, North,
North-West, and so on). This setting has no effect if there is no free
space remaining for the component.
- Weight X and Weight Y. Adjust the weight settings to determine
how much space a component should be given relative to other components
in its row or column when the container window is resized. Generally, weight
values range from zero to one. Components with larger weight values get
more space allocated in their row or column when the window is resized.
Components with a weight value of zero always retain their preferred
size for that dimension. If all the components in a row or column have
a weight of zero, any extra space goes to the outer edges of the row or
column and the components stay the same size.
- Insets. The Insets determine the minimum amount of external
space on each of the four sides of the component. You can enter numbers
manually or use the inset buttons. The buttons are divided into four sets
that enable you to adjust the insets for each side separately, the left
and right insets simultaneously, the top and bottom insets simultaneously,
or all four insets simultaneously.
As you change the insets, you will see the inset area marked by a yellow
background in the right pane.
- It is often helpful to sketch out the way you
want your layout to look before you use the GridBag customizer.
- See Also
- About Layout Managers
- Setting the Layout Manager
- Setting Layout Properties
Legal Notices