AnyLogic enables users to choose any colors they like for their graphical elements. This can be done using the Colors dialog box.

Colors dialog

The Colors dialog box is commonly used when the user wants to specify some custom Fill color or Line color for a shape or a model element, that is not present among the set of most used colors.

To choose some custom color using the Colors dialog box

  1. Open the drop-down list containing the set of most used colors by clicking inside the Fill color or Line color control. We name this control the color picker.

  1. Click in the Other Colors... section. The Colors dialog box will be opened.
  2. Choose the color you like using the provided controls (they are described below).
  3. When finished, click OK to apply your changes.
The dialog contains two pages (Standard and Spectrum) and the common area at the bottom of the dialog.

Standard page

The Standard page allows the user to choose the color from the set of standard colors. When you hover the mouse over some color from the palette, the tool tip displaying the symbolic name of this color is shown.

Spectrum page

The Spectrum page enables to choose some custom color. You can choose any color from the spectrum by dragging the handle in the Colors area. Or you can specify Red, Green and Blue color components directly in the controls below.

The common area of the dialog contains the following controls:

The preview pane in the lower right corner shows the color, currently set for the edited model element (Current) and the color, currently selected in the color chooser's palette (New).

Chosen color - Displays the code string corresponding to the currently chosen color: either the color name constant, or the color constructor. You can use this field to define a custom color as described here.

Copy - The button copies the string from the Chosen color field to the Clipboard. You can paste it later on in the corresponding Dynamic property of some another shape you want to be painted with this color.

Transparency - The slider sets the transparency for the color. The transparency value is displayed in the control to the right of the slider. 255 corresponds to fully opaque color, 0 - to fully transparent.

Defining a color using Java expression

You can set a color by specifying a valid Java expression in the Chosen color field.

Several alternative syntaxes are allowed. You can specify:

Color constants

The most popular colors are listed on the Standard page of the Colors dialog (see figure below).

In the case you want to use some other color, you can choose it on the Spectrum page of the dialog by dragging the handle in the Colors area, or specifying Red, Green and Blue color components evidently.

Set of standard colors (as shown in the Colors dialog)

In the case you want to dynamically switch to some of these standard colors, you may refer to the required color using the name of the corresponding constant. The table below lists the names of color constants for all the standard colors shown above. Use indexes (A..J, 1..14) to find the correspondence between cells of these tables.

1 black darkGray dimGray gray silver lightGrey gainsboro whiteSmoke white red
2 darkRed maroon fireBrick brown indianRed lightCoral rosyBrown snow mistyRose salmon
3 tomato darkSalmon coral orangeRed lightSalmon feldspar sienna seaShell saddleBrown chocolate
4 sandyBrown peachPuff peru linen bisque darkOrange burlyWood tan antiqueWhite navajoWhite
5 blanchedAlmond papayaWhip moccasin orange wheat oldLace floralWhite darkGoldenRod goldenRod cornsilk
6 gold khaki lemonChiffon paleGoldenRod darkKhaki yellow olive lightGoldenRodYellow lightYellow beige
7 ivory oliveDrab yellowGreen darkOliveGreen greenYellow chartreuse lawnGreen lime green darkGreen
8 limeGreen forestGreen lightGreen paleGreen darkSeaGreen honeyDew seaGreen mediumSeaGreen springGreen mintCream
9 mediumSpringGreen mediumAquaMarine aquamarine turquoise lightSeaGreen mediumTurquoise cyan darkCyan teal darkSlateGray
10 paleTurquoise lightCyan azure darkTurquoise cadetBlue powderBlue lightBlue deepSkyBlue skyBlue lightSkyBlue
11 steelBlue dodgerBlue lightSlateGray slateGray lightSteelBlue cornflowerBlue royalBlue blue mediumBlue darkBlue
12 navy midnightBlue lavender ghostWhite slateBlue lightSlateBlue darkSlateBlue mediumSlateBlue mediumPurple blueViolet
13 indigo darkOrchid darkViolet mediumOrchid magenta darkMagenta purple violet plum thistle
14 orchid violetRed mediumVioletRed deepPink hotPink paleVioletRed lavenderBlush crimson pink lightPink

Plus to the “classical” colors listed above, you can use any other "custom" colors. You create your color as the instance of standard Java class Color.

Defining custom colors dynamically

Defining transparent colors

Please note that transparent elements take significantly longer time to draw and may therefore slow down the model execution.

Making elements' components invisible at runtime

Please see Java documentation on class Color for more information.

Related topics