Class WButtonGroup


public class WButtonGroup
extends WObject
A class for grouping radio buttons logically together.

A button group manages a set of radio buttons, making them exclusive of each other.

It is not a widget, but instead provides only a logical grouping. Radio buttons are aware of the group in which they have been added, see WRadioButton.getGroup(). When a button is deleted, it is automatically removed its button group.

It allows you to associate id's with each button, which you may use to identify a particular button. The special value of -1 is reserved to indicate no button.

See Also:
  • Constructor Details

    • WButtonGroup

      public WButtonGroup​(WObject parent)
      Creates a new empty button group.
    • WButtonGroup

      public WButtonGroup()
      Creates a new empty button group.

      Calls this((WObject)null)

  • Method Details

    • addButton

      public void addButton​(WRadioButton button, int id)
      Adds a radio button to the group.

      You can assign an id to the button. If id is -1, then a unique id will be generated.

      See Also:
      removeButton(WRadioButton button)
    • addButton

      public final void addButton​(WRadioButton button)
      Adds a radio button to the group.

      Calls addButton(button, - 1)

    • removeButton

      public void removeButton​(WRadioButton button)
      Removes a radio button from the group.

      See Also:
      addButton(WRadioButton button, int id)
    • getButton

      public WRadioButton getButton​(int id)
      Returns the button for the given id.

      See Also:
      getId(WRadioButton button), addButton(WRadioButton button, int id)
    • getId

      public int getId​(WRadioButton button)
      Returns the id for the given button.

      See Also:
      getButton(int id), addButton(WRadioButton button, int id)
    • getId

      public java.lang.String getId()
      Description copied from class: WObject
      Returns the (unique) identifier for this object

      For a WWidget, this corresponds to the id of the DOM element that represents the widget. This is not entirely unique, since a WCompositeWidget shares the same id as its implementation.

      By default, the id is auto-generated, unless a custom id is set for a widget using WWidget.setId(String). The auto-generated id is created by concatenating WObject.getObjectName() with a unique number.

      getId in class WObject
    • getButtons

      public java.util.List<WRadioButton> getButtons()
      Returns the buttons in this group.
    • getCount

      public int getCount()
      Returns the number of radiobuttons in this group.
    • getCheckedId

      public int getCheckedId()
      Returns the id of the checked button.

      Returns the id of the currently checked button, or -1 if no button is currently checked.

    • setCheckedButton

      public void setCheckedButton​(WRadioButton button)
      Sets the currently checked radiobutton.

      The button button of this group is checked. A value of null will uncheck all radiobuttons.

      Initially, no button is checked.

      See Also:
    • getCheckedButton

      public WRadioButton getCheckedButton()
      Returns the checked radiobutton.

      If there is no radiobutton currently checked this function returns null.

      See Also:
      setCheckedButton(WRadioButton button), getSelectedButtonIndex()
    • setSelectedButtonIndex

      public void setSelectedButtonIndex​(int idx)
      Sets the currently checked radiobutton.

      Sets the idx'th radiobutton checked. A value of -1 will uncheck all radiobuttons.

      Initially, no button is checked.

    • getSelectedButtonIndex

      public int getSelectedButtonIndex()
      Returns the index of the checked radiobutton.

      The index reflects the order in which the buttons have been added to the button group. Use getCheckedId() if you want to know the id of the button that is currently checked. If there is no radiobutton selected this function returns -1.

      See Also:
    • checkedChanged

      public Signal1<WRadioButton> checkedChanged()
      Signal emitted when a button was checked.

      The argument passed is the new getCheckedButton().

    • setFormData

      protected void setFormData​(WObject.FormData formData)
      setFormData in class WObject