aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes ButtonGroup with JRadioButton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ButtonGroup with JRadioButton" Watch "ButtonGroup with JRadioButton" New topic
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I like Nathans better than mine. I am going to start doing it that way.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ButtonGroup with JRadioButton