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: 4587456
Votes 0
Synopsis implementation of FlowLayout.LayoutContainer does not comply to
Category guides:none
Reported Against tiger-beta , merlin-beta3
Release Fixed 1.5(tiger)
State 11-Closed, Verified, bug
Priority: 4-Low
Related Bugs 4629262
Submit Date 10-DEC-2001
Description
.




Specification for constructor (public FlowLayout(int align,
int hgap, int vgap)) of FlowLayout class states:
"... Creates a new flow layout manager with the indicated alignment
and the indicated horizontal and vertical gaps. ...
... hgap - the horizontal gap between components
    vgap - the vertical gap between components ...".

Implementation actually not only divides components by specified
gaps, but also divides components from container borders by gaps.
Such behavior does not comply to specification. Please see the
exaple below.

------------------ Start of DoLayout.java ----------------------
import java.awt.*;

public class DoLayout {

    public static void main(String argv[]) {
        FlowLayout fl = new FlowLayout(FlowLayout.LEFT, 3, 4);

        Container parent = new Container();
        parent.setLayout(fl);

        parent.setSize(800, 600);

        Component comp = new Component(){};
        comp.setSize(50, 20);

        parent.add("Component", comp);

        Component comp2 = new Component(){};
        comp2.setSize(50, 20);

        parent.add("Component2", comp2);

        parent.doLayout();

        System.out.println("Component's size: " + comp.getSize() +
                           ", location: " + comp.getLocation());

        System.out.println("Component2's size: " + comp2.getSize() +
                           ", location: " + comp2.getLocation());
    }
}
------------------ End of DoLayout.java ----------------------
------------------ Output under build 1.4.0-rc-b88------------
~/bugs
javac DoLayout.java;java DoLayout
Component's size: java.awt.Dimension[width=50,height=20], location:
java.awt.Point[x=3,y=4]
Component2's size: java.awt.Dimension[width=50,height=20], location:
java.awt.Point[x=56,y=4]
~/bugs
--------------------------------------------------------------

Comment: Though such behavior does not comply to spec it is looking
reasonable. Probably it would be better if one will add to specification
that
gaps are palced not only between components but also between
components and borders.

======================================================================
Work Around
N/A
Evaluation
I believe the specification for this layout manager should be changed to indicate that each component added to the container sans the first one will be padded with a hgap and vgap.
  xxxxx@xxxxx   2002-03-22 

I added a suggested fix after discussing this with   xxxxx@xxxxx   : 
we should document that the hgap and vgap also apply to the space between 
components and the Container border.  
  xxxxx@xxxxx   2002-05-23

Fixed for tiger.  Reviewed by Brent, approved by CCC.
  xxxxx@xxxxx   2003-08-11
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang