• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

BoxLayout can't be shared exception?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 =)
 
Bartender
Posts: 563
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Albert Johnstone
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 563
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic