JDK-4587456 : implementation of FlowLayout.LayoutContainer does not comply to
  • Type: Bug
  • Component: docs
  • Sub-Component: guides
  • Affected Version: 1.4.0,5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: linux,solaris_2.5
  • CPU: x86,sparc
  • Submitted: 2001-12-10
  • Updated: 2017-05-16
  • Resolved: 2003-09-13
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: 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
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b19 VERIFIED IN: tiger
14-06-2004

PUBLIC COMMENTS .
10-06-2004

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
23-05-2002

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
23-05-2002