Radio Buttons

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
  1. Drag the  Radio Buttons element from the  Controls palette into the graphical editor.
  2. Navigate to the Properties.
  3. 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. Linking controls to parameters is thoroughly described here.
  4. 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). 

Properties

General

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 level – If selected, the control will be also visible on the upper level 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.

Action

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.

Appearance

Background color – The control specifies the background color for the control. 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.

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

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).

Advanced

Visible – The control's visibility. The control is visible when the specified expression evaluates to true, Otherwise it is and 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.

Functions

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

Parameter:
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.

Parameters:
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/disabling the control

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.

Parameter:
yes - If true, the control will be enabled, if false - disabled. 

Executing the control action programmatically

Function

Description

void action()

Executes the action associated with the control.

Control position

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.

Parameter:
x - the new value of X coordinate

void setY(double y)

Sets the Y coordinate of the control.

Parameter:
y - the new value of Y coordinate

void setPos(double x,
double y)

Sets new coordinates for the control.

Parameters:
x - the new value of x coordinate
y - the new value of y coordinate

Control visibility

Function

Description

boolean isVisible()

Returns the visibility of the control.

void setVisible(boolean v)

Sets the visibility of the control.

Parameter:
v - visibility: if true - the control is set to be visible, if false - not visible.


Related topics

 Aligning Shapes

 API Reference: ShapeRadioButtonsGroup Class