AnyLogic
Expand
Font size

Edit box

Edit box is a basic text control that enables a user to type a small amount of text.

Edit boxes are commonly used for modifying values of variables and parameters at the model runtime. You can link this control to a variable or a parameter of type String, double or int. In this case when the user changes the content of the edit box, the linked variable/parameter immediately gets this content as its value.

However, if your variables or parameters are of type int, we recommend to modify their values using sliders. boolean variables are best controlled using check boxes.

You may have a look at the demo model below. It shows how to link the edit box to a parameter rate of the Source object in a simple process model.

Demo model: Edit Box Linked To Parameter Of Flowchart Block Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files).

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. If you want to bind the edit box with a variable or a parameter of type String, double or int (on changing the value of the edit box, the linked parameter/variable immediately gets this value), select the Link to checkbox and enter the name of the variable/parameter that you want to link to the edit box.
  4. You can also define any action to be executed each time the value of the edit box is changed. Type the code you want to execute into the Action section (the current content of the edit box is available here as value (local variable of String type)).

Properties

General

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

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

Link to — If you want to bind the edit box with a variable or a parameter of type String, double or int (on changing the value of the edit box, the linked parameter/variable immediately gets this value), select this checkbox and enter the name of the variable/parameter that you want to link to the edit box.

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

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

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

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

Action

Here you can type 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 (local variable of String type).

Appearance

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

Text color — The control specifies the color of the text displayed inside the edit box. 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 text displayed inside the edit box. In the field to the right (pt.) you can adjust the size of the text.

Italic — If checked, the text displayed inside the edit box will be italicized.

Bold — If checked, the text displayed inside the edit box 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 not visible.

Replication — Here you specify the number of 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 edit box will be considered as a part of the agent’s icon.

Functions

Obtaining the current value
Function Description
double getDoubleValue() Returns the current double value of the edit box.
Function throws an exception when the value isn’t a number.
int getIntValue() Returns the current int value of the edit box.
Function throws an exception when the value isn’t 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. Doesn’t execute user action code.
If value-type is numeric and the given text isn’t a valid number, nothing will be changed, and if text is a number but not within [min, max], 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 callAction parameter is true.
If value-type is numeric and the given text isn't a valid number, nothing will be changed, and if text is a number but not within [min, max], it will be corrected to min or max.

text — the new text.
callAction — if true, user action code (if there is any) will be executed.
void setText(double value) Sets the numeric value of the edit box with value type ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT.
Doesn’t execute 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 value type ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT.
Executes user action code (if there is any) if callAction parameter is true.

value — the new value (double or int).
callAction — if true, 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.
Doesn’t execute user action code.
Values range
Function Description
double getMin() Returns the minimum value of the edit box.
This function may only be used in edit boxes with value type ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT.
double getMax() Returns the maximum value of the edit box.
This function may only be used in edit boxes with value type ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT.
void setRange(double min, double max) Sets the minimum and the maximum values of the edit box with numeric value-type: ShapeControl.TYPE_DOUBLE, ShapeControl.TYPE_INT.
Doesn't execute 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 such 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 numeric value-type: ShapeControl.TYPE_DOUBLE, ShapeControl.TYPE_INT.
If the current edit box value changes, it executes user action code (if there is any) in the same thread — if callAction parameter is true.
If 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 such range.

min — the new minimum value.
max — the new maximum value.
callAction — if true, 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 X coordinate.
void setY(double y) Sets the Y coordinate of the control.

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