• Post Reply Bookmark Topic Watch Topic
  • New Topic

JRadioButton

 
Lesole Mphinyane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how make radio buttons in order to make a single choice..? this is what i have.
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a ButtonGroup, then add all JRadioButtons to it.

Getting the selected JRadioButton isn't going to work without checking them all though, since ButtonGroup only allows you to retrieve the selected button's model.
 
Lesole Mphinyane
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Use a ButtonGroup, then add all JRadioButtons to it.

Getting the selected JRadioButton isn't going to work without checking them all though, since ButtonGroup only allows you to retrieve the selected button's model.


i tried, now it doesnt show anything.. look at this.
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the JRadioButton API and you will find a link to the Swing tutorial on "How to Use Buttons" that contains a working example.
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just because you added the radio buttons to the button group doesn't mean you shouldn't add them to the panel as well. The panel is for showing, the button group is for the mutual exclusiveness. You need both.

And please, do not use a null LayoutManager. Read this instead, and use a combination of proper LayoutManagers to get what you want.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!