Name: bkR10101 Date: 10/16/2001
Specification for
public GridLayout(int rows, int cols, int hgap, int vgap) states:
".....
Creates a grid layout with the specified number of rows and columns.
All components in the layout are given equal size. In addition, the
horizontal and vertical gaps are set to the specified values.
Horizontal gaps are placed at the left and right edges, and between
each of the columns. Vertical gaps are placed at the top and bottom
edges, and between each of the rows.
One, but not both, of rows and cols can be zero, which means that any
number of objects can be placed in a row or in a column.
All GridLayout constructors defer to this one
.....
"
Below is the code that demostrates behavior of layoutContainer that does
not comply to specification.
================= layoutContainerTests.java ==============================
import java.awt.*;
class layoutContainerTests {
public static void main(String argv[]) {
int rows = 1;
int cols = 1;
int hgap = 2;
int vgap = 3;
GridLayout gl = new GridLayout(rows, cols, hgap, vgap);
Container parent = new Container();
parent.setLayout(gl);
Insets insets = parent.getInsets();
int x = insets.left + insets.right + cols * 3 + (cols + 1) * hgap;
int y = insets.top + insets.bottom + rows * 5 + (rows + 1) * vgap;
parent.setSize(x, y);
System.out.println("parent x " + x);
System.out.println("parent y " + y);
Component comp = new Component(){};
parent.add(comp, "comp");
gl.layoutContainer(parent);
Dimension dim = comp.getSize();
System.out.println("comp width " + dim.width);
System.out.println("comp height " + dim.height);
}
}
=============== end of layoutContainerTests.java =========================
Output under JDK version "1.4.0-beta3-b81" ===============================
cd bugs
~/bugs
java layoutContainerTests
parent x 7
parent y 11
comp width 7
comp height 11
~/bugs
==========================================================================
So GridLayout having one row and one column was created. Its hgap is set
to 2 and vgap is set to 3. Then parent having size 7 x 11 was created. But
after
call to layoutContainer size of comp is 7 x 11, but accroding to spec it
must be 3 x 5.
======================================================================