public class RadioButton extends CheckButton
A RadioButton is somewhat similar to a CheckButton, but it is shown as an empty circle (rather than an empty square) and the selected Button in the group us shown with a dot inside (rather than a check mark).
However, while a CheckButton can be used alone to choose between two states, a RadioButton is used together in a group of other (related) RadioButtons to offer a choice of one of those Buttons. Only a single Button in a group can the active at any one time.
To create a group of RadioButtons, you first create a RadioGroup
and then construct the RadioButtons passing them that group object.
RadioGroup group; RadioButton opt1, opt2, opt3; group = new RadioGroup(); opt1 = new RadioButton(group, "Option _1"); opt2 = new RadioButton(group, "Option _2"); opt3 = new RadioButton(group, "Option _3");You can get the active option at any time with RadioButtonGroup's
getActive() method. And while you can still
connect a handler to the ToggleButton's
TOGGLED signal, the
GROUP_TOGGLED signal is
provided as a convenience.
You should generally place related RadioButtons together, better if
disposed vertically, as this makes them easier to scan visually - in other
words, pack them into a VBox. It is also frequently a good idea to
place a descriptive Label at the top of the Container holding the
RadioButtons. A Frame is a possible way to fit both requirements,
as you can use it to place the RadioButtons altogether with a Label at the
top:
Frame option;
VBox buttons;
// Create a Frame with a descriptive Label and without outline...
option = new Frame("Option:");
option.setBorderWidth(3);
option.setShadowType(ShadowType.NONE);
// ... and with a VBox to layout the RadioButtons
buttons = new VBox(false, 2);
option.add(buttons);
buttons.add(opt1);
buttons.add(opt2);
buttons.add(opt3);
In your applications you will usually use RadioButtons you have two or more
mutually exclusive values for an option. Note that if such values are
equivalent to the concept of enable/disable a given option,
CheckButton or ToggleButton are probably a better
alternative. In the same way, if you have too many possible values, you
should consider using a ComboBox instead, or even think about the
possibility of simplifying your user interface.
ToggleButton.ToggledButton.ClickedWidget.ButtonPressEvent, Widget.ButtonReleaseEvent, Widget.Destroy, Widget.Draw, Widget.EnterNotifyEvent, Widget.FocusInEvent, Widget.FocusOutEvent, Widget.Hide, Widget.KeyPressEvent, Widget.KeyReleaseEvent, Widget.LeaveNotifyEvent, Widget.MapEvent, Widget.MotionNotifyEvent, Widget.PopupMenu, Widget.QueryTooltip, Widget.ScrollEvent, Widget.SizeAllocate, Widget.UnmapEvent, Widget.VisibilityNotifyEvent| Constructor and Description |
|---|
RadioButton(RadioGroup group,
String label)
Create a new RadioButton with the given label.
|
| Modifier and Type | Method and Description |
|---|---|
RadioGroup |
getGroup()
Get the RadioGroup that encloses this RadioButton and the others that
belonging to the same mutual exclusion group.
|
connect, getActive, setActiveconnect, emitClicked, getAlignmentX, getAlignmentY, getImage, getLabel, getRelatedAction, getRelief, setAlignment, setFocusOnClick, setImage, setLabel, setRelatedAction, setReliefadd, getChildren, remove, setBorderWidthactivate, addEvents, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, destroy, getAllocatedHeight, getAllocatedWidth, getAllocation, getCanDefault, getCanFocus, getHasFocus, getName, getParent, getPreferredHeightForWidthMinimum, getPreferredHeightForWidthNatural, getPreferredHeightMinimum, getPreferredHeightNatural, getPreferredWidthForHeightMinimum, getPreferredWidthForHeightNatural, getPreferredWidthMinimum, getPreferredWidthNatural, getRequestMode, getRequisition, getSensitive, getStyleContext, getToplevel, getWindow, grabAdd, grabDefault, grabFocus, grabRemove, hide, isSensitive, overrideBackground, overrideColor, overrideFont, queueDraw, queueDrawArea, realize, setAlignHorizontal, setAlignVertical, setCanDefault, setCanFocus, setEvents, setExpandHorizontal, setExpandVertical, setName, setSensitive, setSizeRequest, setTooltipMarkup, setTooltipText, show, showAllpublic RadioButton(RadioGroup group, String label)
label - The label that will be placed near the RadioButton. If the
text contains an underscore (_) it will be taken
to be the mnemonic for the Widget.public RadioGroup getGroup()