Switching from one layout to another

I have a layout on a JFrame and I want to change that layout with another.

Do you have any idea ?

I tried the setLayout(null)

and after that this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

but it still doesn't work.

It appears that some exception is untreated.

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.layoutContainer(Unknown Source)

at java.awt.Container.layout(Unknown Source)

at java.awt.Container.doLayout(Unknown Source)

at java.awt.Container.validateTree(Unknown Source)

at java.awt.Container.validateTree(Unknown Source)

at java.awt.Container.validateTree(Unknown Source)

at java.awt.Container.validate(Unknown Source)

at javax.swing.RepaintManager.validateInvalidComponents(Unknown Source)

at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)

at java.awt.event.InvocationEvent.dispatch(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

[1624 byte] By [endera] at [2007-11-27 0:40:07]
# 1

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

This line looks a little odd.

The BoxLayout constructor's first argument is the Container that it is supposed to

layout. Fine you might think ... I'm telling BoxLayout to lay out the "this" container

and I am saying to "this" to set the layout to the new BoxLayout thus constructed.

But there's a problem. JFrame's setLayout() method is a bit different to other

containers. In fact the container whose layout gets set is the frame's content pane.

(See the start of the API documentation for JFrame).

So trythis.setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

(I haven't tried this.)

pbrockway2a at 2007-7-11 22:52:46 > top of Java-index,Java Essentials,Java Programming...