Class WButtonGroup
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
addButton
(WRadioButton button) Adds a radio button to the group.void
addButton
(WRadioButton button, int id) Adds a radio button to the group.Signal emitted when a button was checked.getButton
(int id) Returns the button for the given id.Returns the buttons in this group.Returns the checked radiobutton.int
Returns the id of the checked button.int
getCount()
Returns the number of radiobuttons in this group.getId()
Returns the (unique) identifier for this objectint
getId
(WRadioButton button) Returns the id for the given button.int
Returns the index of the checked radiobutton.void
removeButton
(WRadioButton button) Removes a radio button from the group.void
setCheckedButton
(WRadioButton button) Sets the currently checked radiobutton.protected void
setFormData
(WObject.FormData formData) void
setSelectedButtonIndex
(int idx) Sets the currently checked radiobutton.Methods inherited from class eu.webtoolkit.jwt.WObject
getObjectName, remove, setObjectName, tr
-
Constructor Details
-
WButtonGroup
public WButtonGroup()Creates a new empty button group.Note: The
WRadioButtons
associated with thisWButtonGroup
keep a shared_ptr to thisWButtonGroup
. Therefore, you should store aWButtonGroup
in a shared_ptr (e.g. construct it with make_shared) before adding any radio buttons to it.
-
-
Method Details
-
addButton
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.Note:
WButtonGroup
should be owned by a shared_ptr before addButton is called on it!- See Also:
-
addButton
Adds a radio button to the group.Calls
addButton(button, - 1)
-
removeButton
Removes a radio button from the group.- See Also:
-
getButton
Returns the button for the given id.Returns
null
if no button exists for the given id. -
getId
Returns the id for the given button. -
getId
Description copied from class:WObject
Returns the (unique) identifier for this objectFor a
WWidget
, this corresponds to the id of the DOM element that represents the widget. This is not entirely unique, since aWCompositeWidget
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 concatenatingWObject.getObjectName()
with a unique number. -
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
Sets the currently checked radiobutton.The button
button
of this group is checked. A value ofnull
will uncheck all radiobuttons.Initially, no button is checked.
- See Also:
-
getCheckedButton
Returns the checked radiobutton.If there is no radiobutton currently checked this function returns
null
. -
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
Signal emitted when a button was checked.The argument passed is the new
getCheckedButton()
. -
setFormData
- Overrides:
setFormData
in classWObject
-