Java Gui Builder |
|
You are here: | Home > Documentation > JGB Elements Documentation > Radio Element |
Group membership: Controls
Adds a radio button to the window.
Radio buttons allow selection in a fixed list of choice by showing all available choices on the window at the same time. Usually, the buttons are shown vertically, but it is not required to do so.
Since radio buttons show multiple choices of a group, all radio buttons are part of a group. This group is named in the group attribute.
With the group's name, it is possible to get the value of the current choice by getting the following key in the context: radio.groups. groupname. The object returned from this key is a ButtonGroup.
See How to Use Radio Buttons, a section in The Java Tutorial, for more information about ButtonGroups.
Name | Type | Required | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
group | CDATA | Yes |
Identifies the name of the group in which this radio button participates. See the radio button example for more information on how this works. |
||||||
id | ID | No |
Identifies the name by which this control will be referenced by other parts of the JGB XML file or Java code. |
||||||
mnemonic | CDATA | No |
Identifies the character that will be used as this control's mnemonic. |
||||||
refaction | IDREF | No |
More information forthcoming |
||||||
reflabel | IDREF | No |
Identifies a control that prompts this one. |
||||||
selected | CDATA | No |
Determines whether or not this radio button will be the selected one in the group when the window opens. The last radio button in the group (in document order) with this attribute equal to true will be selected. Literal values
|
||||||
text | CDATA | No |
Specifies the text that will appear on the control. Do not add an underline (_) or ampersand (&) to the text attribute to identify the mnemonic. Use this element's mnemonic attribute for that purpose. |
… <!-- Add two radio buttons, one for each sex. The "Male" radio button will be selected by default. Also, we will add a border around the group, with a proper title. To access the current value, use the following Java code: Builder builder = … builder.build(…); ButtonGroup sexGroup = (ButtonGroup)builder.getObject("radio.groups.sex"); ButtonModel selectedSexModel = sexGroup.getSelected(); if ("sex.male".equals(selectedSexModel.getActionCommand())) { … } --> <panel id="ageGroupPanel" layout="GridLayout" rows="6" columns="1"> <border title="Applicant's sex"/> <radio id="sex.male" group="sex" text="Male" selected="true" mnemonic="m"/> <radio id="sex.female" group="sex" text="Female" mnemonic="f"/> </panel> <!-- To access the current value for the age goup, use the following Java code: Builder builder = … builder.build(…); ButtonGroup ageGroup = (ButtonGroup)builder.getObject("radio.groups.age-group"); ButtonModel selectedAgeGroup = ageGroup.getSelected(); if ("0".equals(selectedAgeGroup.getActionCommand())) { … } --> <panel id="ageGroupPanel" layout="GridLayout" columns="6" columns="1"> <border title="Age Group"/> <radio id="0" group="age-group" text="< 15"/> <radio id="16" group="age-group" text="16-25"/> <radio id="26" group="age-group" text="26-35"/> <radio id="36" group="age-group" text="36-45"/> <radio id="46" group="age-group" text="46-55"/> <radio id="56" group="age-group" text=">= 56"/> </panel> …
Hosted on SourceForge.net |
Valid XHTML 1.0 ! |
Valid CSS ! |
Code Coverage provided by Clover |