Computer Science Canada

BoxLayout error

Author:  Aziz [ Wed Jul 26, 2006 7:16 am ]
Post subject:  BoxLayout error

Why am I getting "BoxLayout cannot be shared" errors? Wtf does this mean? I've switch my layouts around (looks better now anyways), but I've never had this problem before and I just want to know what it means.

Author:  HellblazerX [ Wed Jul 26, 2006 7:33 am ]
Post subject: 

It means that the BoxLayout can only be used with the container it was designed to be used with. See, when you create a new BoxLayout, you have to pass in a container object. Only that container can be used with the BoxLayout. You can't have another container use that BoxLayout. You'll have to create a new one.

Author:  Aziz [ Wed Jul 26, 2006 8:31 am ]
Post subject: 

Thanks, that explain the how, and would explain the why if I didn't figure it out myself.

I was using

code:
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));


In a JFrame or JDialog, while I should've been using getContentPane() for the Container, correct? Well, it solved my problem (using it for a custom dialog)

Author:  Aziz [ Wed Jul 26, 2006 8:35 am ]
Post subject: 

Wtf, no, hold on, why is this giving me the can't be shared error?

code:
panel = new JPanel(new BoxLayout(panel, BoxLayout.PAGE_AXIS));

Author:  rizzix [ Wed Jul 26, 2006 10:03 am ]
Post subject: 

Aziz wrote:
Wtf, no, hold on, why is this giving me the can't be shared error?

code:
panel = new JPanel(new BoxLayout(panel, BoxLayout.PAGE_AXIS));


Umm do this:
code:
panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));


You can definitely file a bug-report on that. Smile


: