AnyLogic
Expand
Font size

Check box

Check box is a control element that can be selected or deselected. It displays its state to the user.

Check boxes are commonly used for modifying values of boolean variables and parameters at the model runtime.

However, if your variables are of type int, we recommend to modify their values using sliders. String and double variables are best controlled using edit boxes.

To add a check box

  1. Drag the  Check Box element from the  Controls palette into the graphical editor.
  2. Navigate to the element’s Properties.
  3. You can bind the check box with a boolean variable or parameter (on changing the value of the check box, the linked parameter/variable immediately gets this value). To link the control to a parameter, select the Link to check box and choose the name of the parameter from the drop-down list on 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.
  4. You can also define any action to be executed each time the value of the check box is changed. Type the code you want to execute into the Action section (the current value of the check box is available here as value (boolean variable: true, if the check box is selected, and false otherwise)).

Properties

General

Name — The name of the check box. It is used to identify and access the control from code.

Ignore — If selected, the check box 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.

Label — Here you can specify the text of the label displayed for the check box.

Link to — If you want to bind the check box with a boolean variable or a parameter (on changing the value of the check box, the linked parameter/variable immediately gets this value), select the Link to check box and enter the name of the variable/parameter that you want to link to this control.

Default value — [Visible if the Link to check box is not selected] Boolean expression determining whether the check box is selected or not by default. If this check box is linked to some variable or parameter, it uses the default value of this variable/parameter as its default value.

Enabled — Here you can specify Boolean expression determining whether the check box is enabled or disabled.

Action

Here you can type the code to execute when the check box is clicked. The current state of the check box is available here as value (boolean variable: true, if the check box is selected, and false otherwise).

Appearance

Text color — The control specifies the color of the label’s text. 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 label’s text. You can adjust the size of the text in the field to the right (pt.).

Italic — If selected, the label’s text will be italicized.

Bold — If selected, the label’s text 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).

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 check box will be considered as a part of the agent’s icon.

Functions

Selecting and clearing
Function Description
boolean isSelected() Returns the state of the check box.
Returns true if it is currently selected, false if not.
void setSelected (boolean yes) Sets the state of the check box. Doesn't execute user action code.

yes — if true — selected, otherwise — not.
void setSelected(boolean yes, boolean callAction) Sets the selected state of the check box.
Executes user action code (if there is any) if callAction parameter is true.

yes — if true — selected, otherwise — not.
callAction — if true, user action code (if there is any) will be executed.
void setValueToDefault() Sets the state of the check box that was 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, false otherwise.
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 associated with the check box action.
Label text
Function Description
String getText() Returns the check box label text.
void setText(Object text) Sets the check box label text.

text — the new label text.
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 check box.

x — the new value of X coordinate.
void setY(double y) Sets the Y coordinate of the check box.

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.
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, where this control is located.
How can we improve this article?