Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4515041
Votes 0
Synopsis GridLayout.layoutContainer isn't doing what spec says
Category guides:none
Reported Against tiger-beta , merlin-beta
Release Fixed 1.5(tiger)
State 11-Closed, Verified, bug
Priority: 4-Low
Related Bugs 4629256 , 4931359
Submit Date 16-OCT-2001
Description





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.

======================================================================
Work Around
N/A
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.
  xxxxx@xxxxx   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   xxxxx@xxxxx  .  
  xxxxx@xxxxx   2002-05-23

Wrote a test app to prove  this is true.  Had changes reviewed by Brent.  CCC approved.  Fixed for tiger.
  xxxxx@xxxxx   2003-09-11
Comments
  
  Include a link with my name & email   

Submitted On 02-DEC-2001
db-inf
I stumbled over the same bug. GridLayout uses the hgap and 
vgap properties only between cells, not at top, bottom, 
left and right edges as documented.



PLEASE NOTE: JDK6 is formerly known as Project Mustang