Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
This applet's contentpane is divided into two panels :
one along the top
and the other one occupying remaining space, ....
which can be done, because the contentpane's layout mode is BorderLayout.
The bottom panel pl2 has its layout mode set initially. Meaning : lay out your components in a grid of 5 rows and as many columns as needed.
The first time the top button is clicked, a different GridLayout is set. Meaning : place components in 2 columns and as many rows as needed.
Then pl2 is told to appear as requested .
All next top button clicks causes this GridLayout to be set .
Meaning : as many rows as needed, 2 columns, horizontal space between components 30 pixels, vertical spacing 15 pixels.
Synchronize visual appearance.
As you can see, all components are equally sized, causing text to become invisible. Natural size is ignored.
GridLayout can be used effectively to make a main division of equally sized panels, for instance, each having its own layout mode set and containing its own components.
It also comes in handy for placing checkboxes or radiobuttons in succeeding rows, for example.