Radio buttons are a group of buttons where only one can be selected at a time.
This control is somewhat similar to a non-editable combo box. We recommend using radio buttons when the number of options offered to the user is small and all of the options need to be displayed simultaneously on the presentation to simplify the decision'making process. If the number of options is significant, use the combo box control instead. If you want to allow a user to select more than one option, use the list box control.
You can link this control to a variable or a parameter of the int type. In this case, when you select an option from the group of buttons, the linked variable or parameter will immediately receive the index of this option as its value. The index is zero-based; the first button in the Radio buttons table has an index of 0, the second one has an index of 1, and so on.
Demo model: Radio Buttons Enabling Other Controls Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files). Demo model: Radio Buttons Enabling Other ControlsOpen the model in your AnyLogic desktop installation.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 link the radio buttons to a variable or a parameter of the int type. In this case, when you select an option from the group of buttons, the linked variable or parameter will immediately receive the index of this option as its value. The index is zero-based; the first button in the Radio buttons table has an index of 0, the second one has an index of 1, and so on. To link the control to a parameter, select the name of the parameter in the Link to property. To learn more about linking controls to parameters, see Linking controls to parameters.
- You can also define an action to execute when the control’s selection changes. Type the code you want to execute in the Action property. The index of the currently selected button is available here as value, a local variable of the int type.
- General
-
Name — The name of the button group. It is used to identify and access the control from code.
Show name — If selected, the name of the button group is displayed in the presentation diagram.
Lock — If selected, the button group is locked; it will not respond to any mouse actions during the model development time. To select it, click its icon in the elements view.
Ignore — If selected, the button group is excluded from the model.
Items — The buttons that compose the group. In the list, specify the labels that will be displayed for options of the button group.
To remove an entry, hover the mouse pointer over the row in the table and clickto the right. Since the order of entries is important, you can rearrange them using the
button located to the left.
Link to — The name of a linked variable or parameter of the int type. When you select an option from the group of buttons, the linked variable or parameter will immediately receive the index of this option as its value.
Default value — [Visible unless Link to is selected] The expression that returns the integer index of the option that will be selected by default. Indexes are zero-based; for example, to select the first button, type 0; to select the second button, type 1, and so on.
Action — The code to execute when any of radio buttons is clicked. The index of the currently selected radio button is available here as value, a local variable of the int type. The index is zero-based; the first option of the button group has an index of 0, the second option has an index of 1, and so on.
- Appearance
-
Orientation — The orientation of the control: either Vertical or Horizontal. Determines how the radio buttons are arranged.
Enabled — A Boolean expression that determines whether radio buttons are enabled or disabled.
Text color — The color of the text labels displaying button names. Click inside the control and select a color from the set of the most used ones or use the Colors dialog box to select a custom color.
Font — Specifies the font size for the label text.
Italic — If selected, the label text will be italicized.
Bold — If selected, the label text will be emphasized in bold.
- Position and size
-
Level — The level to which this control belongs.
X — The X-coordinate of the control’s upper left corner.
Y — The 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).
- Visibility and presentation
-
Visible — The visibility of the control. Can be set to a dynamic expression that makes the control visible when evaluated to true.
Agent presentation — If selected, the control is included in the presentation of the agent. This means that if the agent hosting this control is embedded in another agent, the control will remain visible in that higher-level agent.
Agent icon — If selected, the control is considered as a part of the agent’s icon.
- Expert
-
Replication — The number of copies of this control that you want created. If this field is left empty, only one control will be created. This field can be set to a dynamic expression.
- Selected value
-
Function Description int getValue() Returns the currently selected radio button, -1 if none. void setValue(int index) Selects the radio button with the given index, removes the selection from others.
Does not execute the user action code.
index — the index of the button.void setValue(int index, boolean callAction) Selects the radio button with the given index, removes the selection from others.
Executes the user action code (if any exists), if the callAction parameter is true.
index — the index of the button.
callAction — if true, the 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 value.
Does not execute the 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) Enables or disables the control.
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. - 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.
x — the new value of the X coordinate.void setY(double y) Sets the Y coordinate of the control.
y — the new value of the Y coordinate.void setPos(double x, double y) Sets new coordinates for the control.
x — the new value of the X coordinate.
y — the new value of the Y coordinate. - Visibility
-
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. - Group
-
Function Description ShapeGroup getGroup() Returns the group containing this control. - Level
-
Function Description Level getLevel() Returns the level on which this control is located.
-
How can we improve this article?
-