Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ButtonGroup with JRadioButton

 
Philip Pross
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to tell which radiobutton is select in a buttongroup .... isn't there a better way to find out which is select then this example
if( rbDate.isSelected() == true )
{
type = "1";
}
if( rbEquip.isSelected() == true )
{
type = "2";
}}
if( rbNo.isSelected() == true )
{
type = "4";
}
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can put an action Listener on the Radio Buttons and set your type = "#" to whichever one is selected.
JRadioButton b = new JRadioButton("1");
b.addActionListener() {
public void actionPerformed(ActionEvent e) {
type = "1";
}});
Something like that anyway.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you can set the action command of your radio buttons via the:


method and in your ButtonGroup call :



To get the String you set as the action command of the JRadioButton above.

So your code would look something like :
 
Philip Pross
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alots, for the examples.
Phil
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like Nathans better than mine. I am going to start doing it that way.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic