my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes BoxLayout can't be shared exception? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "BoxLayout can Watch "BoxLayout can New topic
Author

BoxLayout can't be shared exception?

Albert Tarcy
Greenhorn

Joined: Jul 02, 2011
Posts: 4
Hi there,

I'm learning Java from Head First and I'm trying to write a simple GUI program that first asks if the user wants to load a game or start completely over. After that, the user gets to change the values of his character. If the user selected Restore, the TextFields contain the information that he saved last time the game was played.
However, in the method gameGui(), the JVM throws an exception at me saying that Boxlayout can't be shared. I do not understand that at all. Maybe somebody can help =)
The code(Don't worry, the bulk of it is just Swing ;)


Maybe something goes wrong in the panel.removeAll()?
I would be grateful if somebody could help. If you want to see the relatively simple GameCharacter class, here it is:

Thanks in advance for helping =)
Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 557
Please post the exact error message, copied and pasted.

I'm guessing the problem is in line 73. Did you mean,

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

instead of

fieldPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.Y_AXIS));

?

I can't check to make sure that solves the problem and that it's the only problem, so let us know.


Learning Java using Eclipse on OpenSUSE 11.2
Linux user#: 501795
Albert Tarcy
Greenhorn

Joined: Jul 02, 2011
Posts: 4
Greg Brannon wrote:Please post the exact error message, copied and pasted.

I'm guessing the problem is in line 73. Did you mean,

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

instead of

fieldPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.Y_AXIS));

?

I can't check to make sure that solves the problem and that it's the only problem, so let us know.


Oh, haha, what a silly mistake by me! Sorry for not posting the error message.
It works perfectly now, thanks a million!

On a side note, do you think that the program was well written? It's my first attempt at making a GUI with some function, so I'd love to hear some feedback =)
Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 557
Glad I could help.

I won't be able to give your code thorough consideration until later today, but I'm sure others will critque its "fitness." Please accept all comments as constructive criticism. This can be a critical group (but mostly friendly) when given the opportunity to critique code.

Edit: Empty catches aren't popular.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BoxLayout can't be shared exception?