United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4587456 : implementation of FlowLayout.LayoutContainer does not comply to

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

Related Reports

Sub Tasks

Description

Name: idR10193			Date: 12/10/2001


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.

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

                                    

Comments
SUGGESTED FIX

    /**
     * Creates a new flow layout manager with the indicated alignment
     * and the indicated horizontal and vertical gaps.
     * <p>
     * The value of the alignment argument must be one of
     * <code>FlowLayout.LEFT</code>, <code>FlowLayout.RIGHT</code>,
     * or <code>FlowLayout.CENTER</code>.
     * @param      align   the alignment value
     * @param      hgap    the horizontal gap between components and 
                           between the components and the borders of 
                           the Container.  
     * @param      vgap    the vertical gap between components and 
                           between the components and the borders of
                           the Container.
     */
    public FlowLayout(int align, int hgap, int vgap) {

###@###.### 2002-05-23
                                     
2002-05-23
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.
###@###.### 2002-03-22 

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

Fixed for tiger.  Reviewed by Brent, approved by CCC.
###@###.### 2003-08-11
                                     
2002-05-23
PUBLIC COMMENTS

.
                                     
2004-06-10
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger

FIXED IN:
tiger

INTEGRATED IN:
tiger
tiger-b19

VERIFIED IN:
tiger


                                     
2004-06-14



Hardware and Software, Engineered to Work Together