Use GridBag layout

You can use the AWT GridBag layout with Swing and AWT containers to arrange components using a powerful and flexible grid arrangement.

The GridBag layout manager arranges its components in rows and columns. The GridBagConstraints object contains information about the row and column where a component is placed, the number of columns the component should span, and how the component should be sized and positioned within the column.

The visual editor uses a visual grid and other visual cues to help you see where each component is placed in relationship to other components. You can use the Design view to set many of the constraints on components in a GridBag. The Properties view also gives you access to the available properties to control the placement of a component.

Showing the grid for GridBag layout
When using the GridBag layout manager, you can show or hide the grid in Design view.

Adding or moving components within GridBag layout
When you build your application visually using GridBag layout, the visual grid markers help you to move and drop components in the required position.

Adjusting fill, anchor, and inset constraints in GridBag layout
When you use the Swing GridBag layout, the visual editor sets default constraints on components. You can change these constraints using the Properties view or the Customize Layout dialog.

Spanning components across GridBag rows and columns
You can set a component in a GridBag layout to span multiple columns or rows. You can set this in the property constraints or by visually dragging the component in the Design view.

 

Parent topic

Swing and AWT layout managers

 

Related concepts

Layout managers and containers

 

Related tasks

Using BorderLayout
Using BoxLayout
Using CardLayout
Using FlowLayout
Using GridLayout (AWT)