AnyLogic 9
Expand
Font size

Edit box

An Edit box is a basic text field that allows you to type a small amount of text.

Edit boxes are commonly used to modify the values of variables and parameters during model runtime. You can link this control to a variable or a parameter of the following types: String, double, or int. Therefore, when you change the content of the edit box, the linked variable or parameter immediately receives that content as its value.

However, if your variables or parameters are of the int type, we recommend modifying their values using sliders. For boolean variables, use check boxes.

To add an edit box

  1. Drag the  Edit Box element from the  Controls palette into the graphical editor.
  2. Navigate to the Properties view.
  3. To connect the edit box to a variable or a parameter of the String, double, or int type, select the Link to checkbox and enter the name of the variable or parameter that you want to link to the edit box. Once that is done, the linked parameter or variable will immediately receive the new value.
  4. You can also set an action to execute each time the value of the edit box changes. Type the code you want to execute into the Action property. In this context, the current content of the edit box is available as value, a local variable of the String type.

Properties

General

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

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

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

Link to — Select this option to connect the edit box to a variable or parameter of the String, double, or int type. This way, when the value of the edit box changes, the linked parameter or variable will immediately receive a new value.

Minimum value — [Visible if Link to is selected and the type of the linked variable or parameter is int or double] The minimum value that can be entered in the edit box (the lower bound of the value range).

Maximum value — [Visible if Link to is selected and the type of the linked variable or parameter is int or double] The maximum value that can be entered in the edit box (the upper bound of the value range).

Default value — [Visible unless Link to is selected] The expression of the String type that defines the default content of the edit box.

Action — The code to execute when the content of the edit box is modified. The current text of the edit box is available here as value, a local variable of the String type.

Appearance

Enabled — The Boolean expression that defines whether the edit box is enabled or disabled.

Background color — The background color for the edit box. 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.

Text color — The color of the text in the edit box. 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 text in the edit box.

Italic — If selected, the text in the edit box will be italicized.

Bold — If selected, the text in the edit box will be emphasized in bold.

Position and size

Level — The level to which this control belongs.

X — The X-coordinate of the upper left corner of the control.

Y — The Y-coordinate of the upper 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 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.

Functions

Obtaining the current value
Function Description
double getDoubleValue() Returns the current double value of the edit box.
The function throws an exception when the value is not a number.
int getIntValue() Returns the current int value of the edit box.
The function throws an exception when the value is not a number.
String getText() Returns the text of the edit box.
Setting new value
Function Description
void setText(String text) Sets the text of the edit box. Does not execute the user action code.
If the type of the value is numeric and the given text is not a valid number, nothing will be changed. If text is a number but is not within the [min, max] range, it will be corrected to min or max.

text — the new text.
void setText(String text, boolean callAction) Sets the text of the edit box.
Executes user action code (if there is any) if the callAction parameter is true.
If the type of the value is numeric and the given text is not a valid number, nothing will be changed. If and if text is a number but is not within the [min, max] range, it will be corrected to min or max.

text — the new text.
callAction — if true, the user action code (if there is any) will be executed.
void setText(double value) Sets the numeric value of the edit box with the ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT value type.
Does not execute the user action code.

value — the new value (double or int).
void setText(double value, boolean callAction) Sets the numeric value of the edit box with the ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT value type.
Executes the user action code (if there is any) if the callAction parameter is true.

value — the new value (double or int).
callAction — if true, the user action code (if there is any) will be executed.
void setValueToDefault() Sets the text of the edit box to what was provided as the default one.
Does not execute the user action code.
Values range
Function Description
double getMin() Returns the minimum value of the edit box.
This function may only be used in the edit boxes with the ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT value type.
double getMax() Returns the maximum value of the edit box.
This function may only be used in the edit boxes with the ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT value type.
void setRange(double min, double max) Sets the minimum and the maximum values of the edit box with a numeric value type: ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT.
Does not execute the user action code.
If the edit box is configured to work with int values, the given [min, max] range may be automatically corrected to have integer bounds (within the given double bounds).
This function does nothing if the edit box already has a range.

min — the new minimum value.
max — the new maximum value.
void setRange(double min, double max, boolean callAction) Sets the minimum and maximum values of the edit box with a numeric value type: ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT.
If the current edit box value changes, it executes the user action code (if there is any) in the same thread, if the callAction parameter is true.
If the edit box is configured to work with int values (see ShapeControl.TYPE_INT), the given [min, max] range may be automatically corrected to have integer bounds (within the given double bounds).
This function does nothing if the edit box already has a range.

min — the new minimum value.
max — the new maximum value.
callAction — if true, the user action code (if any exists) will be executed if current edit box value changes.
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) 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 edit box.
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.
Background and text color
Function Description
void setBackgroundColor(Color backgroundColor) Sets the background color of this edit box.

backgroundColor — the desired background color.
void setTextColor(Color textColor) Sets the text color of this edit box.

textColor — the desired text color.
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?