BoxLayout & Borders

Hi !

I'm trying to add a JPanel to a panel using BoxLayout. When I set a border to the subPanel, it deasapear ! Here is the code :

// Inside a class extending JPanel

privatevoid initComponents()

{

setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

setBorder(BorderFactory.createEtchedBorder());

mandatoryPanel =new JPanel(new SpringLayout());

initMandatoryPanelComponents();

mandatoryPanel.setPreferredSize(new Dimension(700, 150));

mandatoryPanel.setMinimumSize(new Dimension(700, 150));

mandatoryPanel.setBorder(BorderFactory.createEtchedBorder());

add(mandatoryPanel);

}

When I comment the line where border is set, the panel is displayed correctly. Else, nothing is displayed.

Can anyone help me ?

[1114 byte] By [Linouxa] at [2007-10-2 16:48:22]
# 1
Is it possible that adding the border makes your preferred size and min size conflict? Try making your min size somewhat less than the preferred size.
BaltimoreJohna at 2007-7-13 17:59:25 > top of Java-index,Desktop,Core GUI APIs...
# 2
> Is it possible that adding the border makes your> preferred size and min size conflict? Try making your> min size somewhat less than the preferred size.Nya nya.
hiwaa at 2007-7-13 17:59:25 > top of Java-index,Desktop,Core GUI APIs...
# 3
> Nya nya.What does that mean? That I was completely off base?
BaltimoreJohna at 2007-7-13 17:59:25 > top of Java-index,Desktop,Core GUI APIs...
# 4
No I already tried to set only preferedSize, or not to set the *Size at all, but no changes appears...
Linouxa at 2007-7-13 17:59:25 > top of Java-index,Desktop,Core GUI APIs...
# 5

In my tests I got the following results using the following code:

//jPanel1 = new JPanel();

jPanel1 = new JPanel(new SpringLayout());

//jPanel1.setLayout(new GridBagLayout());

jPanel1.setBorder(BorderFactory.createEtchedBorder());

jPanel1.add(getJButton1(), new GridBagConstraints());

jContentPane.add(jPanel1, null);

If I use a GridBagLayout, everything seems fine. However, if I use the SpringLayout the etchedBorder causes problems. It seems that the two are mutally exclusive in some way that I don't know about.

BaltimoreJohna at 2007-7-13 17:59:25 > top of Java-index,Desktop,Core GUI APIs...