Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

basic radiobutton question

 
Adam Confino
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Swing Gurus,

I am trying to work through some beginner tutorials and noticed that my radiobutton would allow you to check all of the options. Do the buttons need to be placed in some type of special container? My code is below:



Thanks. I appreciate your time and help very much,
Adam
 
Brian Cole
Author
Ranch Hand
Posts: 907
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam Confino wrote:I am trying to work through some beginner tutorials and noticed that my radiobutton would allow you to check all of the options. Do the buttons need to be placed in some type of special container?


You need to use a ButtonGroup. It's not a container in the GUI sense, but it's a non-graphical object that deselects the other buttons in the group when a button is selected.

If you're looking at beginner tutorials, they should mention ButtonGroup along with JRadioButton. Sun's tutorial does.


Then again, a beginner tutorial should not be having you do setLayout(null) and setBounds(...) either. It's brittle and in the long run no easier than doing it the right way.
 
Adam Confino
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a bunch! I appreciate your help!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic