United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4515041 : GridLayout.layoutContainer isn't doing what spec says

Details
Type:
Bug
Submit Date:
2001-10-16
Status:
Closed
Updated Date:
2004-03-20
Project Name:
JDK
Resolved Date:
2003-11-05
Component:
docs
OS:
solaris_2.5,generic
Sub-Component:
guides
CPU:
sparc,generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.0,5.0
Fixed Versions:
5.0 (tiger)

Related Reports

Sub Tasks

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
PUBLIC COMMENTS

.
                                     
2004-06-10
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) {
                                     
2004-06-11
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
                                     
2004-06-11
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
generic
tiger

FIXED IN:
tiger

INTEGRATED IN:
tiger
tiger-b21

VERIFIED IN:
tiger


                                     
2004-06-14



Hardware and Software, Engineered to Work Together