BoxLayout Exception

privatevoid createTable()

{

for (int j = 0; j < truthTable.length; j++)

{

JPanel panel =new JPanel();

panel.setBackground(Color.white);

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

panel.add(new JLabel(labels[j]));

for (int k = 0; k < truthTable[0].length; k++)

panel.add(new JLabel(truthTable[j][k]));

add(panel);

}

}

publicvoid showTable()

{

JFrame frame =new JFrame("Truth Table");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().add(this);

frame.pack();

frame.setVisible(true);

}

The method createTable works fine. But when I run the showTable method I get the following error:

BoxLayout can't be shared

I don't understand why, any suggestions?

Thank You

[1551 byte] By [java4life87a] at [2007-11-27 0:02:54]
# 1
The JPanel in createTable only has scope within that method.God knows what this does then:frame.getContentPane().add(this);Does your class extend a Component?This is the cause of the sharing error:panel.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
TuringPesta at 2007-7-11 15:55:57 > top of Java-index,Java Essentials,Java Programming...
# 2

I figured out that that is the line because when I commented it out it I did not get the error.

My class extends JPanel

when I used only one BoxLayout reference I still got the same error

private void createTable()

{

///////////////// THIS WAS ADDED ///////////////////////////////////

BoxLayout boxLayout = new BoxLayout(this, BoxLayout.Y_AXIS);

for (int j = 0; j < truthTable.length; j++)

{

JPanel panel = new JPanel();

panel.setBackground(Color.white);

panel.setLayout(boxLayout);

panel.add(new JLabel(labels[j]));

for (int k = 0; k < truthTable[0].length; k++)

panel.add(new JLabel(truthTable[j][k]));

add(panel);

}

}

java4life87a at 2007-7-11 15:55:57 > top of Java-index,Java Essentials,Java Programming...
# 3
> when I used only one BoxLayout reference I still got> the same error> Please read my first post.
TuringPesta at 2007-7-11 15:55:57 > top of Java-index,Java Essentials,Java Programming...