Using GridBagLayout (AWT)

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

The GridBagLayout 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 cells the component should span, and how the component should be sized and positioned within the cell.

The visual editor uses red, dotted lines to indicate the current borders of the grid. The column and row numbers are also labeled. The rows and columns begin their numbering with 0. So, the upper left corner cell is labeled originally as 0,0. As you add components, the rows and columns are numbered sequentially based on the previously used number.

GridBagLayout grid

Note: If a grid number is skipped, it indicates that there are no components that are using that specific grid x or grid y setting. This can occur if you add and remove lots of components or move components around. The GridBagLayout allows x and y values to be skipped, and simply lays out the x,y values in order, relative to other x,y values set for other components, even if values are skipped.

To specify how the grid displays, see Specifying grid display preferences for containers.

Related concepts
Layout managers and containers
Related tasks
Specifying grid display preferences for containers

(C) Copyright IBM Corporation 1999, 2004. All Rights Reserved.