AnyLogic AnyLogic
Expand
Font size
All Implemented Interfaces:
com.anylogic.engine.internal.Child, Locatable2D, AggregatableAnimationElement, HasLevel, LevelElement, SVGElement, java.io.Serializable, java.lang.Cloneable

public class ShapeComboBox
extends ShapeInputControl
Combo box control. Embeds a JComboBox component.
Author:
AnyLogic North America, LLC https://anylogic.com
See Also:
Serialized Form

Nested Class Summary

Nested classes/interfaces inherited from class com.anylogic.engine.presentation.ShapeControl

ShapeControl.ValueType

Field Summary

Fields 
java.lang.String value
The currently selected item of the combo box that can be accessed in the overridden action() method.
Use getValue() to obtain the currently selected item from other places
Modifier and Type Field Description

Fields inherited from class com.anylogic.engine.presentation.ShapeControl

TYPE_DOUBLE, TYPE_INT, TYPE_STRING

Fields inherited from class com.anylogic.engine.presentation.Shape

UNKNOWN_NAME

Constructor Summary

Constructors 
ShapeComboBox​(Presentable p, boolean ispublic, double x, double y, double width, double height, java.awt.Color backgroundColor, java.awt.Color textColor, boolean enabled, java.awt.Font font, java.lang.String[] items, boolean editable, ShapeControl.ValueType valueType)
Creates a persistent combo box control.
ShapeComboBox​(Presentable p, boolean ispublic, double x, double y, double width, double height, java.awt.Color backgroundColor, java.awt.Color textColor, java.awt.Font font, java.lang.String[] items, boolean editable, ShapeControl.ValueType valueType)
Deprecated.
may be removed in future releases
Constructor Description

Method Summary

All Methods Instance Methods Concrete Methods 
void executeUserAction​(java.lang.String value)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
double getDoubleValue()
Returns the current double value of the combo box.
Method throws an exception when the value isn't a number.
int getIntValue()
Returns the current int value of the combo box.
Method throws an exception when the value isn't a number.
This method differs from getValueIndex(): it tries to parse the textual value as number
java.lang.String[] getItems()
Returns array of String items currently used in the combo box drop-down list
The returned array should not be changed by user
java.lang.String getValue()
Returns the currently selected text item.
int getValueIndex()
Returns the index of the currently selected text item or -1 when this is editable combobox and it doesn't contain entered value.
void setItems​(java.lang.String[] items)
Sets new items for this combo box
This method preserves current combo box value: if it is editable if it is not-editable and current value is contained in new texts This method doesn't execute user action code (even if current selection changes)
This method throws an exception if this combo box has numeric value-type (ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT) and some item(s) can't be parsed as a number.
void setItems​(java.lang.String[] items, boolean callAction)
Sets new items for this combo box
This method preserves current combo box value: if it is editable if it is not-editable and current value is contained in new texts
void setValue​(double value)
Sets the numeric value of the combo box with value type ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT.
Doesn't execute user action code
void setValue​(double value, boolean callAction)
Sets the numeric value of the combo box with value type ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT.
Executes user action code (if any exists) if callAction parameter is true
void setValue​(java.lang.String text)
Sets the selected text item of the combo box.
Doesn't execute user action code
void setValue​(java.lang.String text, boolean callAction)
Sets the selected text item of the combo box.
Executes user action code (if any exists) if callAction parameter is true.
If value-type is numeric and the given text isn't a valid number, nothing will be changed
void setValueIndex​(int valueIndex)
Selects the item with the given index.
Doesn't execute user action code
void setValueIndex​(int valueIndex, boolean callAction)
Selects the item with the given index.
Executes user action code (if any exists) if callAction parameter is true.
Modifier and Type Method Description

Methods inherited from class com.anylogic.engine.presentation.ShapeInputControl

postSVGShapeSpecificAttributes

Methods inherited from class com.anylogic.engine.presentation.ShapeControl

action, clone, contains, executeAction, getHeight, getPresentable, getWidth, isEnabled, randomPointInside, restoreOwner, setEnabled, setHeight, setValueToDefault, setWidth

Methods inherited from class com.anylogic.engine.presentation.Shape

canHandleClick, findSVGElement, getDrawMode, getGroup, getLevel, getName, getRotation, getScaleX, getScaleY, getSVGId, getX, getY, isJava2DSwingPresentation, isPublic_xjal, isSVGPresentation, isVisible, onAggregatorVisibilityChanged, onClick, randomPointInside, removeSVGFromOwner, removeSVGImage, resetSVGState, setLevel, setPos, setPos, setPublic_xjal, setRotation, setScale, setScale, setScaleX, setScaleY, setVisible, setX, setY, updateDynamicProperties, updateDynamicPropertiesStructural, updateSVGProperties

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods inherited from interface com.anylogic.engine.markup.AggregatableAnimationElement

initializeInternal, postInitialize

Field Detail

value

@AnyLogicInternalAPI
public java.lang.String value
The currently selected item of the combo box that can be accessed in the overridden action() method.
Use getValue() to obtain the currently selected item from other places

Constructor Detail

ShapeComboBox

public ShapeComboBox​(Presentable p,
                     boolean ispublic,
                     double x,
                     double y,
                     double width,
                     double height,
                     java.awt.Color backgroundColor,
                     java.awt.Color textColor,
                     java.awt.Font font,
                     java.lang.String[] items,
                     boolean editable,
                     ShapeControl.ValueType valueType)
Deprecated.
may be removed in future releases

ShapeComboBox

public ShapeComboBox​(Presentable p,
                     boolean ispublic,
                     double x,
                     double y,
                     double width,
                     double height,
                     java.awt.Color backgroundColor,
                     java.awt.Color textColor,
                     boolean enabled,
                     java.awt.Font font,
                     java.lang.String[] items,
                     boolean editable,
                     ShapeControl.ValueType valueType)
Creates a persistent combo box control. You should override the action() method, in which you can access the current selection of combo box as "value".
Parameters:
p - the presentable object owning this control
ispublic - if true, the control is visible on container's presentation
x - the x coordinate
y - the y coordinate
width - the width
height - the height
backgroundColor - the background color
textColor - the text color
enabled - the initial enabled state
font - the text font
items - the array of text labels of the combo box
valueType - the type of the value edited in the combo box, supported types: ShapeControl.TYPE_STRING, ShapeControl.TYPE_DOUBLE, ShapeControl.TYPE_INT

Method Detail

setValue

public void setValue​(java.lang.String text)
Sets the selected text item of the combo box.
Doesn't execute user action code
Parameters:
text - the new selected text item

setValue

public void setValue​(java.lang.String text,
                     boolean callAction)
Sets the selected text item of the combo box.
Executes user action code (if any exists) if callAction parameter is true.
If value-type is numeric and the given text isn't a valid number, nothing will be changed
Parameters:
text - the new selected text item
callAction - if true user action code (if any exists) will be executed

setValueIndex

public void setValueIndex​(int valueIndex)
Selects the item with the given index.
Doesn't execute user action code
Parameters:
valueIndex - the item index

setValueIndex

public void setValueIndex​(int valueIndex,
                          boolean callAction)
Selects the item with the given index.
Executes user action code (if any exists) if callAction parameter is true.
Parameters:
valueIndex - the item index
callAction - if true user action code (if any exists) will be executed

setValue

public void setValue​(double value)
Sets the numeric value of the combo box with value type ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT.
Doesn't execute user action code
Parameters:
value - the new value (double or int)

setValue

public void setValue​(double value,
                     boolean callAction)
Sets the numeric value of the combo box with value type ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT.
Executes user action code (if any exists) if callAction parameter is true
Parameters:
value - the new value (double or int)
callAction - if true user action code (if any exists) will be executed

getValue

public java.lang.String getValue()
Returns the currently selected text item.
Returns:
the currently selected text item

getValueIndex

public int getValueIndex()
Returns the index of the currently selected text item or -1 when this is editable combobox and it doesn't contain entered value.
Returns:
the index of the currently selected text item or -1

getIntValue

public int getIntValue()
Returns the current int value of the combo box.
Method throws an exception when the value isn't a number.
This method differs from getValueIndex(): it tries to parse the textual value as number
Returns:
the current int value of the combo box

getDoubleValue

public double getDoubleValue()
Returns the current double value of the combo box.
Method throws an exception when the value isn't a number.
Returns:
the current double value of the combo box

getItems

public java.lang.String[] getItems()
Returns array of String items currently used in the combo box drop-down list
The returned array should not be changed by user
Returns:
array of String items currently used in the combo box drop-down list

setItems

public void setItems​(java.lang.String[] items)
Sets new items for this combo box
This method preserves current combo box value:
  • if it is editable
  • if it is not-editable and current value is contained in new texts
This method doesn't execute user action code (even if current selection changes)
This method throws an exception if this combo box has numeric value-type (ShapeControl.TYPE_DOUBLE or ShapeControl.TYPE_INT) and some item(s) can't be parsed as a number.
Parameters:
items - the array of String items to be placed in the combo box drop-down list

setItems

public void setItems​(java.lang.String[] items,
                     boolean callAction)
Sets new items for this combo box
This method preserves current combo box value:
  • if it is editable
  • if it is not-editable and current value is contained in new texts
Parameters:
items - the array of String items to be placed in the combo box drop-down list
callAction - if true and selection changes, user action code (if any exists) will be executed

executeUserAction

@AnyLogicInternalAPI
public void executeUserAction​(java.lang.String value)
Description copied from interface: SVGElement
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
Specified by:
executeUserAction in interface SVGElement
Overrides:
executeUserAction in class Shape
How can we improve this article?