Class ButtonGroup

java.lang.Object
com.codename1.ui.ButtonGroup
All Implemented Interfaces:
ActionSource<ActionEvent>

public class ButtonGroup extends Object implements ActionSource<ActionEvent>

This class is used to create a multiple-exclusion scope for com.codename1.ui.RadioButton. Creating a set of com.codename1.ui.RadioButton components with the same ButtonGroup object means that only one com.codename1.ui.RadioButton can be selected among those within the specific ButtonGroup.

CheckBox cb1 = new CheckBox("CheckBox No Icon");
cb1.setSelected(true);
CheckBox cb2 = new CheckBox("CheckBox With Icon", icon);
CheckBox cb3 = new CheckBox("CheckBox Opposite True", icon);
CheckBox cb4 = new CheckBox("CheckBox Opposite False", icon);
cb3.setOppositeSide(true);
cb4.setOppositeSide(false);
RadioButton rb1 = new RadioButton("Radio 1");
RadioButton rb2 = new RadioButton("Radio 2");
RadioButton rb3 = new RadioButton("Radio 3", icon);
new ButtonGroup(rb1, rb2, rb3);
rb2.setSelected(true);
hi.add(cb1).add(cb2).add(cb3).add(cb4).add(rb1).add(rb2).add(rb3);
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of ButtonsGroup
    Adds all the radio buttons to the group
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a RadioButton to the group
    void
    Adds an action listener to all the buttons in the group
    void
    Adds the RadioButtons to the group
    void
    Clears the selection such that none of the buttons in the ButtonGroup are selected.
    int
    Returns the number of buttons in the group.
    getRadioButton(int index)
    Returns the radio button at the given group index
    Return the selected radio button within the group
    int
    Return the index of the selected button within the group
    boolean
    Returns whether a radio button in the group is selected.
    void
    removes a RadioButton from the group
    void
    Removes an action listener from all the buttons in the group
    void
    setSelected(int index)
    Sets the selected Radio button by index
    void
    Selects the given radio button

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
     
    boolean
    Indicates whether some other object is "equal to" this one.
    final Class
    Returns the runtime class of an object.
    int
    Returns a hash code value for the object.
    final void
    Wakes up a single thread that is waiting on this object's monitor.
    final void
    Wakes up all threads that are waiting on this object's monitor.
    Returns a string representation of the object.
    final void
    Causes current thread to wait until another thread invokes the method or the method for this object.
    final void
    wait(long timeout)
    Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
    final void
    wait(long timeout, int nanos)
    Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
  • Constructor Details

    • ButtonGroup

      public ButtonGroup()
      Creates a new instance of ButtonsGroup
    • ButtonGroup

      public ButtonGroup(RadioButton... rb)

      Adds all the radio buttons to the group

      Parameters
      • rb
  • Method Details

    • addAll

      public void addAll(RadioButton... rb)

      Adds the RadioButtons to the group

      Parameters
      • rb: a RadioButtons to add
    • add

      public void add(RadioButton rb)

      Adds a RadioButton to the group

      Parameters
      • rb: a RadioButton to add
    • remove

      public void remove(RadioButton rb)

      removes a RadioButton from the group

      Parameters
      • rb: a RadioButton to remove
    • clearSelection

      public void clearSelection()
      Clears the selection such that none of the buttons in the ButtonGroup are selected.
    • getButtonCount

      public int getButtonCount()

      Returns the number of buttons in the group.

      Returns

      number of radio buttons in the group

    • isSelected

      public boolean isSelected()

      Returns whether a radio button in the group is selected.

      Returns

      true if a selection was made in the radio button group

    • getSelectedIndex

      public int getSelectedIndex()

      Return the index of the selected button within the group

      Returns

      the index of the selected button within the group

    • getSelected

      public RadioButton getSelected()

      Return the selected radio button within the group

      Returns

      the selected radio button within the group

    • setSelected

      public void setSelected(RadioButton rb)

      Selects the given radio button

      Parameters
      • rb: the radio button to set as selected
    • setSelected

      public void setSelected(int index)

      Sets the selected Radio button by index

      Parameters
      • index: the index of the radio button to mark as selected
    • getRadioButton

      public RadioButton getRadioButton(int index)

      Returns the radio button at the given group index

      Parameters
      • index: offset within the group starting with 0 and no larger than getButtonCount()
      Returns

      the radio button instance

    • addActionListener

      public void addActionListener(ActionListener<ActionEvent> al)

      Adds an action listener to all the buttons in the group

      Parameters
      • al: the listener
      Specified by:
      addActionListener in interface ActionSource<ActionEvent>
    • removeActionListener

      public void removeActionListener(ActionListener<ActionEvent> al)

      Removes an action listener from all the buttons in the group

      Parameters
      • al: the listener
      Specified by:
      removeActionListener in interface ActionSource<ActionEvent>