I faced the following java error “exception in thread awt-eventqueue-0” java awt awterror boxlayout can t be shared”
- Exception in thread “AWT-EventQueue-0” java.awt.AWTError: BoxLayout can’t be shared
at javax.swing.BoxLayout.checkContainer(Unknown Source)
at javax.swing.BoxLayout.invalidateLayout(Unknown Source)
at javax.swing.BoxLayout.addLayoutComponent(Unknown Source)
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at javax.swing.JFrame.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at GUI.run(GUI.java:64)
I used import of box layout at program.
import javax.swing.BoxLayout;
Maybe you want to program box layout in java,and the exception in thread awt-eventqueue-0” java awt awterror boxlayout can t be shared error maybe because you missed creating a reference object for box layout.
For rich GUI elements in java,these layouts are useful.java awt awterror can be fixed if you can create a reference object first.
creation of box layout,so the above error maybe due to that you missed creation of box layout. You can just create a box layout object first ,like as i shown in the below code and than you can call with “window.add(boxlayoutpane);”
// this is initial creation of box layout
JPanel boxlayoutpane = new JPanel();
boxlayoutpane.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
window.setContentPane(boxlayoutpane);
when you want to use the created box layout object
//calling the box layout object…
boxlayoutpane.add(display); // boxlayoutpane is the reference object for box layout
boxlayoutpane.add(action1);
boxlayoutpane.add(action2);
boxlayoutpane.add(action3);
window.add(boxlayoutpane);