Issue
How do I add radio buttons to a button group using NetBeans?
Once I add them, how do I get selected radio button from the button group?
Solution
I highly recommend reading this excellent tutorial. Here's an excerpt of code from the article that satisfies your question on how to create and add buttons to a ButtonGroup:
JRadioButton birdButton = new JRadioButton(birdString);
birdButton.setSelected(true);
JRadioButton catButton = new JRadioButton(catString);
//Group the radio buttons.
ButtonGroup group = new ButtonGroup();
group.add(birdButton);
group.add(catButton);
As far as getting which item is selected, you basically need to iterate through the items in the group calling isSelected
.
Answered By - Mark Elliot