AnyLogic 9
Expand
Font size

Button

The control typically used to allow a user to interactively manipulate the model. You can define a specific action (in the button’s Action property) to be performed each time the user clicks the button at model runtime.

Demo model: Buttons Change Parameter Value Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files).

To add a button

  1. Drag the  Button element from the  Controls palette into the graphical editor.
  2. Navigate to the button’s properties.
  3. In the Label edit box, type the text that you want to appear inside the button. Optionally, you can customize the appearance of the text (font, size, and so on) in the Appearance section.
  4. In the Action section of the button’s properties, type the Java code you want to execute when the button is clicked. Be sure to end each line of code with a semicolon.

Properties

General

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

Show name — If selected, the name of the button is displayed in the presentation diagram.

Lock — If selected, the button 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 is excluded from the model.

Label — Specifies the text of the label displayed on the button. Can be set to a dynamic expression.

Enabled — Specifies whether the button is enabled or disabled. Can be set to a dynamic expression.

Action — Enter the Java code to be executed when the button is clicked.

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 colors, or specify a color by its RGB code. You can also copy and paste a color.

Font size — Specifies the font size for the label’s text.

Italic — If selected, italicizes the label text.

Bold — If selected, the text in the label will be bold.

Position and size

Level — The level to which this control belongs.

X — The X coordinate of the top left corner of the control.

Y — The Y coordinate of the top left corner of the control.

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 be 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 — Dynamically specifies the number of copies of this control to create. Leave empty to place a single control.

Functions

Enabling and disabling
Function Description
boolean isEnabled() Checks whether the button is enabled or disabled. Returns true if enabled, otherwise false.
void setEnabled(boolean yes) Sets the control to be 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 button.
Label text
Function Description
String getText() Returns the button label text.
void setText(Object text) Sets the button 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 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.
Size
Function Description
double getWidth() Returns the width of the control in pixels.
double getHeight() Returns the height of the control in pixels.
void setWidth(double width) Sets the width of the control to the passed value.

width — The new width.
void setHeight(double height) Sets the height of the control to the passed value.

height — The new height.
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 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?