The GridBagLayout Layout Manager

Like GridLayout, GridBagLayout positions components in a grid. Unlike GridLayout, in which you explicitly specify the number of rows and columns in the grid, GridBagLayout determines the number of rows and columns from constraints placed upon the components it lays out. Also, unlike GridLayout, GridBagLayout allows components to span more than one grid cell— components may also overlap, as we shall soon discover.

GridBagLayout is capable of handling nearly any layout situation; however, it is one of the most complex and difficult classes in the AWT to use. Developers are often put off by its complexity, but it's an extremely useful layout manager. For that reason, we will apply a three-pronged approach to covering ...

Get Graphic Java™ 1.2, Volume I: AWT, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.