-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.2.0
-
sparc
-
solaris_2.5.1
Name: bk70084 Date: 05/28/98
If BoxLayout is used to layout JPanel which contains
another JPanel the layout of other components is not
done correctly.
The layout that I was expecting was that "label1", "panel1" and "label4" would extend right across
the window horizontally (right - left justified) and take-up approximately equal space vertically.
The layout I see is "label1" and "label4" starting half way across the window and extend to the right
limit of the window (aligned with "label3"). While "panel1" does extend the full width of the window.
The following code demonstrates the problem:
import java.awt.*;
import java.awt.event.*;
import java.awt.swing.*;
import java.awt.swing.border.*;
public class Test extends JPanel
{
public Test()
{
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
JLabel label1 = new JLabel("Label1", SwingConstants.CENTER);
label1.setBorder(new TitledBorder(LineBorder.createBlackLineBorder(), "Label1"));
label1.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
add(label1);
JPanel panel1 = new JPanel();
panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS));
panel1.setBorder(new TitledBorder(LineBorder.createBlackLineBorder(), "Panel1"));
panel1.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
add(panel1);
JLabel label2 = new JLabel("Label2", SwingConstants.CENTER);
label2.setBorder(new TitledBorder(LineBorder.createBlackLineBorder(), "Label2"));
label2.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
panel1.add(label2);
JLabel label3 = new JLabel("Label3", SwingConstants.CENTER);
label3.setBorder(new TitledBorder(LineBorder.createBlackLineBorder(), "Label3"));
label3.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
panel1.add(label3);
JLabel label4 = new JLabel("Label4", SwingConstants.CENTER);
label4.setBorder(new TitledBorder(LineBorder.createBlackLineBorder(), "Label4"));
label4.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
add(label4);
}
public static void main(String args[])
{
try
{
JFrame frame = new JFrame("Test");
WindowListener l = new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
};
frame.addWindowListener(l);
Test test = new Test();
frame.getContentPane().add(BorderLayout.CENTER, test);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setSize(screenSize.width / 2, screenSize.height / 2);
frame.setLocation(screenSize.width / 4, screenSize.height / 4);
frame.show();
}
catch (Exception e)
{
System.err.println("ERROR: " + e);
e.printStackTrace(System.out);
}
}
}
(Review ID: 28674)
======================================================================
- relates to
-
JDK-4374833 BoxLayout behaves differently with JFrame, JPanel and JSplitPane
-
- Closed
-