JDK-4515041 : GridLayout.layoutContainer isn't doing what spec says
  • Type: Bug
  • Component: docs
  • Sub-Component: guides
  • Affected Version: 1.4.0,5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,solaris_2.5
  • CPU: generic,sparc
  • Submitted: 2001-10-16
  • Updated: 2017-05-16
  • Resolved: 2003-11-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Description

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.

======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b21 VERIFIED IN: tiger
14-06-2004

EVALUATION Appears the first component in a GridLayout that only has 1 column and 1 row does not have the hgap and vgap applied to it. ###@###.### 2002-03-22 In order to preserve backwards compatibility, I would prefer to change the spec to document the way GridLayout currently behaves. This code is so old that I would be afraid of breaking existing applications if we change the implementation. Discussed this with ###@###.###. ###@###.### 2002-05-23 Wrote a test app to prove this is true. Had changes reviewed by Brent. CCC approved. Fixed for tiger. ###@###.### 2003-09-11
11-06-2004

SUGGESTED FIX /** * Creates a grid layout with the specified number of rows and * columns. All components in the layout are given equal size. * <p> * In addition, the horizontal and vertical gaps are set to the * specified values. Horizontal gaps are placed between each of * the columns. Vertical gaps are placed between each of the rows. * <p> * One, but not both, of <code>rows</code> and <code>cols</code> can * be zero, which means that any number of objects can be placed in a * row or in a column. * <p> * All <code>GridLayout</code> constructors defer to this one. * @param rows the rows, with the value zero meaning * any number of rows * @param cols the columns, with the value zero meaning * any number of columns * @param hgap the horizontal gap * @param vgap the vertical gap * @exception IllegalArgumentException if the value of both * <code>rows</code> and <code>cols</code> is * set to zero */ public GridLayout(int rows, int cols, int hgap, int vgap) {
11-06-2004

PUBLIC COMMENTS .
10-06-2004