| Author |
ButtonGroup with JRadioButton
|
Philip Pross
Ranch Hand
Joined: Jan 17, 2001
Posts: 76
|
|
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
Ranch Hand
Joined: Jul 11, 2001
Posts: 15229
|
|
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
Joined: Oct 18, 2000
Posts: 4121
|
|
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 :
|
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
|
 |
Philip Pross
Ranch Hand
Joined: Jan 17, 2001
Posts: 76
|
|
Thanks alots, for the examples. Phil
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15229
|
|
I like Nathans better than mine. I am going to start doing it that way.
|
 |
 |
|
|
subject: ButtonGroup with JRadioButton
|
|
|