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.
- While editing you may need the Redo, Undo, Pad, and Test Layout buttons in the toolbar above the right pane.
- 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
- 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
fills is marked with green in the right pane.
You can also adjust the Fill constraint using the Grid Size buttons.
- 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.
- Anchor. The Anchor constraint enables you to place the component
in one of eleven 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.
You can also adjust the Anchor constraint using the Grid Size buttons.
- 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.
As you change the insets, you will see the inset area marked by a green
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