Minor FlowLayout fixes (nChildren -> getComponentCount(), ...)
Giles Lean
giles at nemeton.com.au
Sat Aug 1 17:32:33 PDT 1998
>Submitter-Id: kaffe-user
>Originator: Giles Lean
>Organization: Giles Lean <giles at nemeton.com.au> +61 3 9480 2118
Nemeton Pty. Ltd. fax +61 3 9480 1771
PGP Fingerprint (DA68EE41) 9F FB 28 37 81 F2 AC F3 8A B0 37 E5 73 CF 39 E7
>Confidential: no
>Synopsis: Minor FlowLayout fixes (nChildren -> getComponentCount(), ...)
>Severity: non-critical
>Priority: medium
>Category:
>Class: sw-bug
>Release:
>Environment:
System: NetBSD topaz.nemeton.com.au 1.3E NetBSD 1.3E (TOPAZ) #1: Sun May 17 17:02:53 EST 1998 giles at topaz.nemeton.com.au:/a/NetBSD/current-build/src/sys/arch/i386/compile/TOPAZ i386
Architecture: Unknown
Machine: Unknown
>Description:
The current FlowLayout code lays out code incorrectly:
(i) in the presence of a Frame with a MenuBar the components
laid out by FlowLayout are under the MenuBar
(ii) components are horizontally shifted right
Problem (i) is fixed by using parent.insets.top appropriately.
Problem (ii) is improved (possibly fixed) by using the
getComponent() and getComponentCount() methods rather than
nChildren and the array children[].
PROBLEM: after these fixes are made, the Frame size is not
correct. The calculation of the dimensions in FlowLayout
seems OK, and I think this bug was hidden by the previous
improper placement of components when parent.insets was
ignored.
>How-To-Repeat:
The following code will show the layout problems:
import java.awt.*;
public class tl extends Frame {
static public void main(String argv[]) {
Frame fr = new Frame("tl ");
fr.setLayout(new FlowLayout());
fr.add(new Button("one"));
fr.add(new Button("two"));
fr.add(new Button("three"));
MenuBar mb = new MenuBar();
Menu file = new Menu("File");
file.add(new MenuItem("Close"));
file.add(new MenuItem("Exit"));
mb.add(file);
fr.setMenuBar(mb);
fr.pack();
fr.setVisible(true);
}
}
>Fix:
Index: libraries/javalib/java/awt/FlowLayout.java
===================================================================
RCS file: /a/Kaffe/CVS/kaffe/libraries/javalib/java/awt/FlowLayout.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -c -r1.1.1.1 -r1.2
*** FlowLayout.java 1998/08/01 16:18:16 1.1.1.1
--- FlowLayout.java 1998/08/01 23:45:49 1.2
***************
*** 55,61 ****
}
for ( int i = start; i <= end; i++) {
! Component c = target.children[i];
if ( c.height > hMax ) {
hMax = c.height;
}
--- 55,61 ----
}
for ( int i = start; i <= end; i++) {
! Component c = target.getComponent(i);
if ( c.height > hMax ) {
hMax = c.height;
}
***************
*** 82,92 ****
Insets in = target.insets;
int mw = target.width - in.left - in.right;
int width = hgap;
! int ypos = vgap;
int rowfirst = 0;
! for ( int i = 0; i < target.nChildren; i++) {
! Component c = target.children[i];
if ( ! c.isVisible) {
continue;
}
--- 82,94 ----
Insets in = target.insets;
int mw = target.width - in.left - in.right;
int width = hgap;
! int ypos = in.top + vgap;
int rowfirst = 0;
! int nChildren = target.getComponentCount();
!
! for ( int i = 0; i < nChildren; i++) {
! Component c = target.getComponent(i);
if ( ! c.isVisible) {
continue;
}
***************
*** 108,114 ****
width = hgap;
}
}
! alignComps( target, rowfirst, target.nChildren-1, width, ypos);
}
public Dimension minimumLayoutSize( Container parent) {
--- 110,116 ----
width = hgap;
}
}
! alignComps( target, rowfirst, nChildren-1, width, ypos);
}
public Dimension minimumLayoutSize( Container parent) {
***************
*** 123,130 ****
int w = 0;
int h = 0;
! for ( int i=0; i<parent.nChildren; i++) {
! Component c = parent.children[i];
if ( c.isVisible) {
Dimension dc = min ? c.getMinimumSize() : c.getPreferredSize();
w += dc.width + hgap;
--- 125,134 ----
int w = 0;
int h = 0;
! int nChildren = parent.getComponentCount();
!
! for ( int i=0; i<nChildren; i++) {
! Component c = parent.getComponent(i);
if ( c.isVisible) {
Dimension dc = min ? c.getMinimumSize() : c.getPreferredSize();
w += dc.width + hgap;
More information about the kaffe
mailing list