"The grid bag layout is the mother of all layout managers. You can think of a grid bag
layout as a grid layout without the limitations.
"You always need to set the weight fields (weightx and weighty) for each area in a grid bag
layout. If you set the weight to 0, then the area never grows or shrinks beyond its initial
size in that direction. In the grid bag layout for Figure 9–29 on page 426, we set the
weightx field of the labels to be 0. This allows the labels to remain a constant width when
you resize the window. On the other hand, if you set the weights for all areas to 0, the
container will huddle in the center of its allotted area rather than stretching to fill it.
Conceptually, the problem with the weight parameters is that weights are properties
of rows and columns, not individual cells. But you need to specify them in terms of
cells because the grid bag layout does not expose the rows and columns. The row
and column weights are computed as the maxima of the cell weights in each row or
column. Thus, if you want a row or column to stay at a fixed size, you need to set the
weights of all components in it to zero.
Note that the weights don’t actually give the relative sizes of the columns. They tell
what proportion of the “slack” space should be allocated to each area if the container
exceeds its preferred size. This isn’t particularly intuitive. We recommend that you set
all weights at 100. Then, run the program and see how the layout looks. Resize the dia-
log to see how the rows and columns adjust. If you find that a particular row or column
should not grow, set the weights of all components in it to zero. You can tinker with
other weight values, but it is usually not worth the effort."
Core Java Vol 1 (8th Ed) P.426/428.
In a nutshell I am a bit confused as to how to see the visual effects of initializing java.awt.GridBagLayout with the weight parameters, and, so far I have tried to update a code snippet, which does not clearly illustrate the above:
Finally I would like to know when it is appropriate to use GridLayout / SpringLayout / FlowLayout? Do you usually use a UI builder? Can I create these layouts and then migrate them to web-interfaces (e.g. JNLP applets or J2EE)?
So far I am aware that these are usually used by tool builders, however, I have noticed that sometimes NetBeans generates lengthy UI generation code which might need to be tweaked in enterprise applications.