The GridBag Layout Manager






The GridBag Layout manager implements three conceptual layers:
  1. the container is divided into a grid

  2. elements of the grid combine to form rectangular cells

  3. components of the cells can occupy all or part of the cell

Here is a first example of using the GridBag layout manager.

This is the output produced.

Note that the size of the components is not as uniform as those shown in figure 6.7 on p. 124 of Late Night Java. It is easy to make them more uniform by inserting one line of code
gbconst.fill = GridBagConstraints.BOTH;
in the program. See the comments in the program to see exactly where this line should be inserted. Setting the GridBagConstraint fill to the constant BOTH makes each component stretch both horizontally and vertically to fill up its cell.