Reputation: 45
I want to return selected radio button name from button group in java :
ButtonGroup bg = new ButtonGroup();
bg.add(radiobutton1);
bg.add(radiobutton2);
bg.add(radiobutton3);
Upvotes: 1
Views: 4279
Reputation: 36
I think you can loop through the radio buttons, for each button if isSelected() is true then call button.getText() to get the name.
for (AbstractButton button : bg.getElements())
if (button.isSelected())
return button.getText();
Upvotes: 2
Reputation: 4084
Why do you want the button name? It isn't of much use. You can, however, get the all of the button references using bg.getElements()
, and you can get the text of each of those references with button.getText()
, both of which are of much more use than the name you gave the button. If you REALLY want the name, you can create the buttons and then call radiobutton1.setName("radiobutton1")
and then use getName()
on the reference.
Upvotes: 1