Although, every AbstractButton can be added to the ButtonGroup (according to the Java API), i wanted to ask, which elements really make sense to get added.
The following two definitely do:
JRadioButtonJRadioButtonMenuItem
I wanted to know about:
JCheckBox<- which, likeJRadioButton, inherits fromJToggleButton- Any other
AbstractButton
ButtonGroupis used to create a multiple-exclusion scope for a set of buttons. Creating a set of buttons with the sameButtonGroupobject means that turning “on” one of those buttons turns off all other buttons in the group.A
ButtonGroupcan be used with any set of objects that inherit fromAbstractButton. Typically aButtonGroupcontains instances ofJRadioButton, JRadioButtonMenuItem, orJToggleButton. It wouldn’t make sense to put an instance ofJButtonorJMenuItemin aButtonGroupbecauseJButtonandJMenuItemdon’t implement the selected state.Initially, all buttons in the group are unselected. Once any button is selected, one button is always selected in the group. There is no way to turn a button programmatically to “off”, in order to clear the button group. To give the appearance of “none selected”, add an invisible
JRadioButtonto the group and then programmatically select that button to turn off all the displayedJRadioButtons. For example, a normal button with the label “none” could be wired to select the invisibleJRadioButton.For examples and further information on using
ButtonGroupssee How to UseJRadioButtons, a section in The Java Tutorial.