Grid Bag Layout

The last of the layout managers available through Java is grid bag layout, which is an extension of the grid layout manager. A grid bag layout differs from grid layout in the following ways:

  • A component can take up more than one cell in the grid.

  • The proportions between different rows and columns do not have to be equal.

  • Components inside grid cells can be arranged in different ways.

To create a grid bag layout, you use the GridBagLayout class and a helper class called GridBagConstraints. GridBagLayout is the layout manager, and GridBagConstraints is used to define the properties of each component to be placed into the cell—its placement, dimensions, alignment, and so on. The relationship between the grid bag, the constraints, and ...

Get Sams Teach Yourself Java 2 in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.