Class ButtonGroup

java.lang.Object
vaadinx.swing.ButtonGroup
All Implemented Interfaces:
Serializable

public class ButtonGroup extends Object implements Serializable
Emulator port of ButtonGroup, accepting AbstractButton subclasses (the JDK class accepts javax.swing.AbstractButton, which our ported subclasses do not extend). Coordinates the buttons' ButtonModels as the JDK's does: getSelection() is the selected button's model, and setSelected(javax.swing.ButtonModel, boolean) deselects the previous selection before selecting the new one.

The JDK keeps a model's group on the model, as a javax.swing.ButtonGroup, which this group is not. So membership is recorded on the emulator's JToggleButton.ToggleButtonModel instead, whose setSelected consults the group where the JDK's consults its own — which is what makes a browser click on a selected radio button leave it selected. A button whose model is some other ButtonModel joins the group's bookkeeping but is never consulted, as a JButton's DefaultButtonModel is not in the JDK.

See Also:
  • Field Details

  • Constructor Details

    • ButtonGroup

      public ButtonGroup()
      Default constructor — empty group, no selection.
  • Method Details

    • add

      public void add(AbstractButton b)
      Adds a button; null is a silent no-op, as in the JDK. A selected newcomer becomes the selection unless there already is one, in which case it is deselected before it joins, so the group does not veto that.
    • remove

      public void remove(AbstractButton b)
      Removes a button; null is a silent no-op, as in the JDK.
    • clearSelection

      public void clearSelection()
      Clears the selection: afterwards no button in the group is selected.
    • getElements

      public Enumeration<AbstractButton> getElements()
    • getSelection

      public ButtonModel getSelection()
    • setSelected

      public void setSelected(ButtonModel m, boolean b)
      Makes m the selection when b is true, deselecting the previous one first. Deselecting is not done here: false does nothing.
    • isSelected

      public boolean isSelected(ButtonModel m)
    • getButtonCount

      public int getButtonCount()