Font size


The control that is commonly used to enable a user to interactively influence the model. You can define a specific action (in the button’s Action property) that will be performed every time the user clicks the button at the 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. Type the text that you want to be displayed inside the button in the Label field. Optionally you can customize the text appearance (font, size, etc.) in the Appearance section.
  4. Type the Java code (that you want to be executed on clicking this button) in the Action section of the button’s Properties. Make sure you terminate each line of the code with a semicolon.



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

Ignore — If selected, the button 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 on the button.

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


Here you can type the code to execute when the button is pressed.


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 some 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 button’s upper left corner.

Y — Y-coordinate of the button’s upper left corner.

Width — The width of the button (in pixels).

Height — The height of the button (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 button’s name will be displayed on the presentation diagram.

Icon — If selected, the button will be considered as a part of the agent’s icon.


Enabling and disabling
Function Description
boolean isEnabled() Tests if the button 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 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.
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 button.

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

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
double getWidth() Returns the width of the button in pixels.
double getHeight() Returns the height of the button in pixels.
void setWidth(double width) Sets the width of the button equal to width.
void setHeight(double height) Sets the height of the button equal to height.
Function Description
boolean isVisible() Returns the visibility of the button.
void setVisible(boolean v) Sets the visibility of the button.

v — visibility: if true — the button is set to be visible, if false — not visible.
Function Description
ShapeGroup getGroup() Returns the group containing this control.
Function Description
Level getLevel() Returns the level, where this control is located.
How can we improve this article?