Grid Layout
--------------
The Grid layout manager subdivides its territory into a matrix of rows and
columns. The number of rows and columns are specified as parameters to
its constructor:
GridLayout(int nRows, int nCols);
You then add components to it. BUT two questions arrise: 1) What if you
add fewer components than the number of cells in the matrix? 2) What if
you add more components than the number of cells in the matrix? Here's an
example which deals with this problem.
This applet takes in as a parameter a number which controls the size
of the array of buttons which populate it. The only difference between
the three applets displayed above is the parameter passed to it. The
first example has a 7 passed to it, the second example has a 9 passed to it,
and the last example has a 13. The grid layout is set to be 3x3 for each
applet and so there are nine cells set up to accomodate components. In the
first example there are left-over cells and so these are left blank. In
the second example we have a perfect fit between the number of cells and
the number of components. Notice in the last case that COLUMNS are added
to accomodate the extra components. The ROWS stay the same, the COLUMNS
change!
The other thing you should notice is that the components are resized to
fit the available space. The Flow layout manager always honors a
component's preferred size. The Grid layout manager takes the opposite
extreme: It always ignores a component's preferred size.
--------------
Another Example: Here's another quick example which actually
employs a Java 1.0 Event handling method to process the button push.
What you do is write stuff in the textfield at the bottom of the applet,
press the button and what you wrote gets written in the top area.
Pretty simple, but slightly more interesting than the last example: