Radio buttons are groups of buttons that can have only one button selected at a time.
This control is somewhat similar to the non-editable combo box. We recommend you to use radio buttons if the number of options you offer a user to choose from is not great and if it is necessary to display all of the options simultaneously on the presentation to simplify the user's decision making procedure. If the number of options is significant, we recommend you to use the combo box control. If you want to allow a user to choose more than one option, you should use the list box control.
You can link this control to a variable or a parameter of type int. In this case on choosing other option from the group of buttons, the linked variable/parameter will immediately get the index of this option as its value. The index is zero-based, i.e. the button defined first in the Radio buttons table has index 0, the second one has index 1, etc.
To add a group of radio buttons
- Drag the Radio Buttons element from the Controls palette into the graphical editor.
- Navigate to the Properties.
- You may want to bind the radio buttons with a variable or a parameter of int type. In this case on choosing other option from the group of buttons, the linked variable/parameter will immediately get the index of this option as its value (please note that the index is zero-based, i.e. the button defined first in the Radio buttons table has index 0, the second one has index 1, etc.). To link the control to a parameter, select the Link to checkbox and choose the name of the parameter from the drop-down list to the right. You can also easily link a control to a parameter of a flowchart block. To learn more about linking controls to parameters, see Linking controls to parameters.
- You can also define the action to be executed on changing the control’s selection. Type the code you want to execute in this case in the Action section (the index of currently selected button is available here as value (local variable of type int).
Name — The name of the buttons group. It is used to identify and access the control from code.
Ignore — If selected, the radio buttons will be excluded from the model.
Visible on upper agent — If selected, the control will be also visible on the upper agent where this agent lives.
Orientation — The orientation of the control: either Vertical or Horizontal. Determines how the radio buttons are arranged.
Radio buttons — Here you define buttons composing the group. In table rows you specify the labels that will be displayed for options of the buttons group.
To remove an entry, select the row in the table and click the “cross” button. Since the order of entries is important, you can rearrange them using arrow keys, located to the right of the table.
Link to — If you want to bind the radio buttons with a variable or a parameter of type int (on choosing other option from the group of buttons, the linked variable/parameter immediately gets an index of this option as its value), select this checkbox and enter the name of the variable/parameter you want to link to the radio buttons.
Default value — [Visible if the Link to checkbox is not selected] The expression that returns integer index of the option that will be selected by default. Indexes are zero-based, i.e. to make the first button selected, type here 0; to select the second button, type 1, and so on.
Enabled — Here you can specify Boolean expression determining whether radio buttons are enabled or disabled.
Here you can type the code to execute when any of radio buttons is clicked. The index of currently selected radio button is available here as value (local variable of type int) The index is zero-based, i.e. the first option of buttons group has index 0, the second 1, and so on.
Text color — The control specifies the color of the text labels displaying button names. Click inside the control and choose a color from the set of the most used ones, or choose a custom color using the Colors dialog box.
Font — Specifies the font family for the labels text. You can adjust the size of the text in the field to the right (pt.).
Italic — If selected, the labels will be italicized.
Bold — If selected, the labels will be emphasized in bold.
- Position and size
Level — Level to which this control belongs.
X — X-coordinate of the control’s upper left corner.
Y — Y-coordinate of the control’s upper left corner.
Width — The width of the control (in pixels).
Height — The height of the control (in pixels).
Visible — The control’s visibility. The control is visible when the specified expression evaluates to true, otherwise it is not visible.
Replication — Here you specify the number copies of this control you want to be created. If you leave this field empty, only one such control will be created.
Show name — If selected, the name of the control will be displayed on a presentation diagram.
Icon — If selected, the radio buttons will be considered as a part of the agent’s icon.
- Selected value
Function Description int getValue() Returns the currently selected radio button, -1 if none. void setValue(int index) Sets selected the radio button with the given index, sets others deselected.
Doesn't execute user action code.
index — the index of the button.
void setValue(int index, boolean callAction) Sets selected the radio button with the given index, sets others deselected.
Executes user action code (if any exists), if callAction parameter is true.
index — the index of the button.
callAction — if true, user action code (if any exists) will be executed.
void setValueToDefault() Sets the value of the radio buttons to what has been provided as the default one.
Doesn’t execute user action code.
- Enabling and disabling
Function Description boolean isEnabled() Tests if the control is enabled or disabled. Returns true if enabled, otherwise false. void setEnabled (boolean yes) Sets the control enabled or disabled.
yes — If true, the control will be enabled, if false — disabled.
- Executing the action
Function Description void action() Executes the action associated with the control.
Function Description double getX() Returns the X coordinate of the control (namely, the X coordinate of its upper left corner). double getY() Returns the Y coordinate of the control (namely, the Y coordinate of its upper left corner). void setX(double x) Sets the X coordinate of the control.
x — the new value of X coordinate.
void setY(double y) Sets the Y coordinate of the control.
y — the new value of Y coordinate.
void setPos(double x, double y) Sets new coordinates for the control.
x — the new value of x coordinate.
y — the new value of y coordinate.
Function Description boolean isVisible() Returns the visibility of the control. void setVisible(boolean v) Sets the visibility of the control.
v — visibility: if true — the control is set to be visible, if false — not visible.
How can we improve this article?