GridBagLayout is the most powerful but also the most difficult to understand of the layouts available in Java. GridBagger is an excellent tool to understand how GridBagLayout works as well as saving time in creating complex layouts and generating the associated source code. It is shareware so please try it out before you register or try the GridBagger demonstration applet.
GridBagger works by allowing the addition of any number of a notional component to a container. Then by altering the GridBagConstraint's for each instance, the resulting layout can be seen instantly. Here's a screen shot of the product in action, with the GridBagConstraint's for component "Button 2" being displayed in the top window. "Button 2" is shown as the currently selected component in the bottom window by being surrounded by a red and green line. By changing the values of the component's GridBagConstraint's the effect can be seen instantly. By dragging the bottom window larger and smaller it's possible to see how GridBagLayout behaves as the space changes.
Once a layout has been designed, pressing GridBagger's "Source" button will give you the Java code for the layout in a new window and this can be either saved to a file or copied into the system clipboard. The source code generated is based on a generic class with the name "SomeComponent" for which the programmer should substitute the actual component class name used. Below is an example of the source generated for two components with simple constraints.