What SWING elements can be added to ButtonGroup that make sense?

Although, everyone AbstractButtoncan be added to ButtonGroup(according to the Java API ), I wanted to ask which elements really make sense to add.

The following two definitely do:

  • JRadioButton
  • JRadioButtonMenuItem

I wanted to know about:

  • JCheckBox<- which, like JRadioButton, inherits fromJToggleButton
  • Any others AbstractButton
+3
source share
2 answers

ButtonGroupused to create a multiple exclusion area for a set of buttons. Creating a set of buttons with the same object ButtonGroupmeans that when you turn on, one of these buttons disables all other buttons in the group.

A ButtonGroup , AbstractButton. ButtonGroup JRadioButton, JRadioButtonMenuItem JToggleButton. JButton JMenuItem ButtonGroup, JButton JMenuItem .

. . "", . "none selected", JRadioButton, , JRadioButtons. , "none" JRadioButton.

ButtonGroups . " JRadioButtons) " Java".

+3

- ButtonGroup, (, ) - - ButtonGroup setSelected :

public void setSelected ( ButtonModel model, boolean selected )
{
    if ( selected || !unselectable )
    {
        super.setSelected ( model, selected );
    }
    else
    {
        clearSelection ();
    }
}

.

+2

All Articles