-
Enhancement
-
Resolution: Won't Fix
-
P5
-
None
-
1.4.0
-
x86
-
windows_nt
Name: sv35042 Date: 10/09/2002
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION :
Windows NT Version 4.0
ADDITIONAL OPERATING SYSTEMS :
Probably all.
A DESCRIPTION OF THE PROBLEM :
The functions
Box.createHorizontalStrut(int width) returns a component
with undefined Maximum Height and
Box.createVerticalStrut(int height) returns a component
with undefined Maximum Width.
To me this is illogical and has serious BoxLayout
ramifications.
Box.createHorizontalStrut(int width) should return a
component with a maximum height of zero and
Box.createVerticalStrut(int height) should return a
component with a maximum width of zero.
These components do have zero height and width respectively
when there is no extra space, but when there is extra space
they expand to fill it.
This makes it impossible to use nested Boxes to achieve
certain desired layouts.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the program and observe the output.
2.
3.
EXPECTED VERSUS ACTUAL BEHAVIOR :
The program creates 3 horizonal boxes nested inside a
vertical box. VerticalGlue is added first to the outer
box, to force the 3 nested boxes to the bottom of the frame.
Each inner horizontal box has HorizontalGlue added first to
force the button to the right edge. A HorizontalStrut is
added after the button to create a right margin.
The expected result is 3 buttons in the bottom right hand
corner with a small right margin.
The actual result is that the 3 buttons appear along the
right hand side. The right margin is correct. However,
the buttons are not all pushed to the bottom by the
vertical glue. Since the 3 horizontal struts do not have a
maximum size defined, the inner 3 boxes expand in size.
The buttons are placed in the center of these expanded
buttons. Hence the buttons spread out.
If the line
innerBox.add(c);
is commented out to remove the right hand margin, then
all the buttons will be forced to the bottom.
If I had desired to spread the buttons out, I would
interleave VerticalGlue and the inner horizontal boxes.
As it is now, I have no way to force the buttons to the
bottom.
Further I don't see what sense it makes to have a
horizontal spacing component have unlimited height.
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import javax.swing.*;
public class Test extends JFrame
{
public static void main(String[] args)
{
new Test();
}
public Test()
{
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Box box = Box.createVerticalBox();
box.add(Box.createVerticalGlue() );
for (int i=0; i < 3; ++i)
{
JButton btn = new JButton("Test" + i);
Box innerBox = Box.createHorizontalBox();
innerBox.add(Box.createHorizontalGlue() );
innerBox.add(btn);
Component c = Box.createHorizontalStrut(32);
innerBox.add(c);
box.add(innerBox);
}
box.setPreferredSize(new Dimension(300, 400) );
this.getContentPane().add(box);
pack();
show();
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
None.
I am about ready to write my own Layout Manager.
(Review ID: 146395)
======================================================================