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.
======================================================================