UIComponent

Base component class that other UI components extend. Not to be instantiated by itself. Most methods in this class are used by other classes that extend this class.

Constructor

new UIComponent(type, …dataopt)

Not to be instantiated by itself. This call is extended dby other UI components.

Parameters:
NameTypeAttributesDescription
typestring

Component type

dataany<optional>
<repeatable>

Additional component init data (used by some UI components).

Classes

UIComponent

Members

(readonly) canRedo :boolean

Gets a boolean indicating if redo operation can be performed on the text. Only applies to components where text can be types (excluding Table cell editor).

Type:
  • boolean

(readonly) canUndo :boolean

Gets a boolean indicating if undo operation can be performed on the text. Only applies to components where text can be types (excluding Table cell editor).

Type:
  • boolean

(readonly) childCount :number

Gets the number of components added to this container.

Type:
  • number

(readonly) children :Array.<Object>

Gets an array of children components. A new array is created each time, so don't use it directly inside a "for(...){}" or "while(...){}" statement. First save it to a variable, then use it in a loop.

Type:
  • Array.<Object>

(readonly) container :boolean

Returns true if the component is a container (other components can be added to it), otherwise returns false.

Type:
  • boolean

(readonly) id :number

Returns a unique ID of the component. ID is reusable, so one component may have an ID of a previously destroyed component.

Type:
  • number

(readonly) parent :Object|undefined

Gets a parent Object. If this component wasn't added to any container component, then null is returned.

Type:
  • Object | undefined

(readonly) screenPosition :Object|null

Gets a position of this component relative to default screen in format {x: number, y: number}. Returns null if component wasn't added to a component that is visible.

Type:
  • Object | null

Methods

addChild(component, …data_or_indexopt) → {this}

Adds a child component to this container component.

Parameters:
NameTypeAttributesDescription
componentObject

UI Component that can be a child of this component.

data_or_indexany<optional>
<repeatable>

Argument to pass some extra data (such as Tab Name to add Panel to Tabs), or index at which to insert the child. By default component is added to the end.

Returns:

Returns an instance of this component.

Type: 
this

addTo(parent, …data_or_indexopt) → {this}

Adds this component to a parent control. Optional index can be supplied to specify at what Z order to insert this component.

Parameters:
NameTypeAttributesDescription
parentObject

Container component to which you want to add this component to.

data_or_indexany<optional>
<repeatable>

Argument to pass some extra data (such as Tab Name to add Panel to Tabs), or index at which to insert the child. By default component is added to the end.

Returns:

Returns an instance of this component for chaining.

Type: 
this

alignment(alignment) → {*}

Sets or gets an alignment of item's label within a List item, Button or Label.

Parameters:
NameTypeDescription
alignment

String (optional) A combination of "top right bottom left center leading trailing"

Returns:
Type: 
*

anchor(anchorsopt) → {this|string}

Sets or gets the anchor style of the component that indicates how to resize this component based on the resizing parent component. Anchors define which sides (top, right, bottom, left) of the component stay attached to the parent when parent gets resized.

Parameters:
NameTypeAttributesDescription
anchorsstring<optional>

Space-separated list of sides to anchor (e.g., "top left"). If omitted, returns the current anchor value.

Returns:

Returns this component when setting, or the current anchor string when getting value.

Type: 
this | string
Example
const txt1 = new TextArea().anchor("top left right"); // Horizontally resizable
const txt2 = new TextArea().anchor("top left bottom"); // Vertically resizable

background(valueopt) → {this|string}

Sets or gets the background color of the component.

Accepts three formats:

  • RGB hex (e.g. "#FF0000")
  • RGBA hex with alpha (e.g. "#FF000050")
  • The string "transparent" (equivalent to "#00000000")
Parameters:
NameTypeAttributesDescription
valuestring<optional>

Background color in supported formats. If omitted, returns the current value.

Returns:

Returns this when setting value, or the current background color string when getting.

Type: 
this | string
Example
component.background("#FF0000");         // Red background
component.background("#00FF0080");       // Semi-transparent green
component.background("transparent");     // Fully transparent

// For Panel and Window components the background value can be a string that contains a mixture of background color,
// image, linear-gradient, radial-gradient, like in CSS in web browsers. Some features may not be supported though.
panel.background("#FF000055 url(images/bg.png) center no-repeat opacity=0.6 10px 15px linear-gradient(#DDDDDD55, #F8F8F855 10%) / auto);
panel.background("url(data:image/png;base64,As8fE4fdt1r.....)")); // supports base64 encoded image string

border(borderopt, updateopt) → {this|Object}

Sets, updates, or gets component border object. Border object may contain only properties that you want to set. See example for border object format.

Parameters:
NameTypeAttributesDescription
borderobject<optional>

Border object. See example for example of border object.

updateboolean<optional>

Set to true to only change specified border properties instead of replacing existing border.

Returns:
Type: 
this | Object
Example
// Border object format with all possible options:
{
    style: string,       // (Required) Valid values: `none`, `line`, `dashed`, `metal`, `etched_raised`, `etched_lowered`, `bevel_raised`, `bevel_lowered`, `soft_raised`, `soft_lowered`
    size: number,        // Border size in pixels (size >= 1).
    padding: string,     // Format: "top right bottom left". Example: "5 10 5 10". Padding can be set even for border of style `none`.
    color: string,       // Only for `line` or `dashed` border style.
    rounded: boolean,    // Set to `true` to make corners rounded in `line` style, or rounded dashes in `dashed` style. Only for `line` or `dashed` border style.
    length: number,      // Length of dashes for `dashed` style.
    spacing: number,     // Length of spaces between dashes in `dashed` style.
    offset: number,      // Offset of dashes from starting location. Can be used to animate dashes.
    text: number,        // Text to show at the top left of the border to make a titled border.
    alignment: string    // A string that defines where border text is placed. Valid words: "left", "center", "right", "leading", "trailing", "above", "below", "top", "bottom". Default is "top left". "above" and "below" means above the border line of below.
    font: object         // Font to use for the border text. For details about font object check example of font() method of this component.
}

bottom(valueopt, reizeopt) → {number|this}

Convenience method to get or set the distance between the bottom edge of this component and the bottom edge of its parent.

Parameters:
NameTypeAttributesDescription
valuenumber<optional>

Distance from the parent's bottom edge to this component's bottom edge.

reizeboolean<optional>

True to resize the height to accommodate for specified bottom position instead of moving the object. false to move the component.

Returns:

Returns the current bottom distance if no argument is provided; otherwise, returns this component.

Type: 
number | this

caretPosition(positionopt) → {this|number}

Set or gets a position of caret in text editing components. Used in some text editing components only.

Parameters:
NameTypeAttributesDescription
positionnumber<optional>
Returns:

Returns this component if argument is provided, otherwise number value.

Type: 
this | number

center(componentopt) → {this}

Positions the component in the center of it's parent component, owner Window (if Window has an owner Window), or screen (Window only). Applies only to components that have position() property (not like menu, menu item, tray icon, etc.)

Parameters:
NameTypeAttributesDefaultDescription
componentObject<optional>
null

If provided, this component will be positioned in the center of the provided component.

Returns:

Returns this component.

Type: 
this

child(index) → {Object}

Returns a child component at specified index or undefined if index is outside of range.

Parameters:
NameTypeDescription
indexnumber

Component index (z order).

Returns:
Type: 
Object

childIndex(child, new_indexopt) → {this|null|number}

Gets or sets the index of a child component within this container. It also changes z-order. When a integer higher than -1 is returned, it also confirms that passed component is indeed a child of this container.

Parameters:
NameTypeAttributesDescription
childObject

Child component

new_indexnumber<optional>

The new index to assign to the child.

Returns:

If new_index is provided, returns this component. If the child is not found in this container, returns null. Otherwise, returns the child's current z-index.

Type: 
this | null | number

color(value) → {string|this}

Sets or gets a foreground color of component (usually text color).

Parameters:
NameTypeDescription
valuestring

Three formats are acceptable, regular RGB "#FF0000", with alpha RGBA "#FF000050", and "transparent" string, which is equivalent to "#00000000".

Returns:

Returns color value if no argument is set, otherwise returns this component.

Type: 
string | this

contextMenu(menuopt) → {ContextMenu|null|this}

Sets or gets context menu component for this UI component.

Parameters:
NameTypeAttributesDescription
menuContextMenu<optional>

ContextMenu component to be assigned to this component. Set to null to remove ContextMenu.

Returns:

Returns the current context menu if no argument is provided; otherwise, returns this component.

Type: 
ContextMenu | null | this

copySelection() → {this}

Copies selected text to clipboard. Applies only to some text editing components, such as TextArea.

Returns:

Returns this component

Type: 
this

cursor(cursor, x, y) → {this}

Sets an cursor to the control. Passing NULL value removes custom cursor.

Parameters:
NameTypeDescription
cursornumber | null | string

A value from Cursor enum, or a relative path to image file for custom cursor icon.

xnumber

Used with custom image cursor to set pointer point on the image.

ynumber

Used with custom image cursor to set pointer point on the image.

Returns:

Returns this component.

Type: 
this

cutSelection() → {this}

Copies selected text to clipboard and removes it from text. Applies only to some text editing components, such as TextArea.

Returns:

Returns this component

Type: 
this

deleteSelection() → {this}

Removes selected text. Applies only to some text editing components, such as TextArea.

Returns:

Returns this component

Type: 
this

destroy(recursiveopt)

Removes the control from it's parent control and from list of all controls. Also prepares this component to be garbage-collected in JavaScript and GUI to free RAM.

Parameters:
NameTypeAttributesDefaultDescription
recursiveboolean<optional>
false

Set to true to also destroy all of its descendants recursively

Returns:

this

dragAction(actionopt) → {string|this}

Sets or gets the drag action for this component (e.g., Copy, Move), and enables or disables dragging accordingly. Passing None disables dragging; all other values enable it.

Parameters:
NameTypeAttributesDescription
actionDragDropAction<optional>

One of enum values: DragDropAction.[None|Copy|Move|CopyOrMove|Link]. None is default.

Returns:

Returns this component if argument is provided, otherwise returns string value as one of the DragDropAction enum values.

Type: 
string | this

dragData(data) → {this}

Sets custom data that should be passed when dragging this component instead of passing component's data, such as text or icon. Without setting this data a default component data will be dragged, such as text, list item, icon, what what ever applies to this component.

Parameters:
NameTypeDescription
datastring | Array.<string>

String data or array of strings. For a list of files or URLs use array or separate them by new line character \n.

Returns:

Returns this component.

Type: 
this

dragDataType(data_type) → {Array.<string>|this}

Sets or gets the types of data that should be transfered during drag operation. The data itself can be set using dragData(...) method. More than one type can be specified by setting multiple arguments or passing an array of values.

Parameters:
NameTypeDescription
data_typeDataType | Array.<DataType>

DataType.[None|Text|Image|...]

Returns:
Type: 
Array.<string> | this
Example
// Usage examples:
label.dragDataType(DataType.Text, DataType.HTML); // setting by multiple arguments
label.dragDataType([DataType.Text, DataType.HTML]); // setting by an array of values
const _types = label.dragDataType(); // getting an array of data types

dropAction(actionopt) → {string|this}

Sets or gets which type of drop action is accepted by the component (e.g., Copy, Move). Setting any action other than None enables dropping on the component. Action None disables dropping.

Parameters:
NameTypeAttributesDescription
actionDragDropAction<optional>

One of enum values: DragDropAction.[None|Copy|Move|CopyOrMove|Link]. None is default.

Returns:

Returns this component if argument is provided, otherwise returns string value as one of the DragDropAction enum values.

Type: 
string | this

dropDataType(data_type) → {Array.<string>|this}

Sets acceptable data types that may be dropped on this component during drag and drop operation.

Parameters:
NameTypeDescription
data_typeDataType | Array.<DataType>

DataType.[None|All|Text|Image|...]. Use All to accept all data types.

Returns:

Returns this component is argument is provided, otherwise returns string[] value.

Type: 
Array.<string> | this
Example
// Usage examples:
label.dropDataType(DataType.All); // Setting to accept all data types
label.dropDataType(.DataType.Text, DataType.HTML); // setting by multiple arguments
label.dropDataType([DataType.Text, DataType.HTML]); // setting by an array of values
const _types = label.dropDataType(); // getting an array of data types

dropMode(modeopt) → {DropMode|this}

Sets a drop mode for components: Table, List, Tree.

Parameters:
NameTypeAttributesDescription
modeDropMode<optional>

Enum value: DropMode.[On|Insert|OnOrInsert]. On - allows data to be dropped on list items. Insert - allows to drop data between list items.

Returns:

Returns this component if an argument is provided; otherwise, returns the current drop mode as one of the DropMode enum values.

Type: 
DropMode | this

editable(editableopt) → {Object|boolean}

Sets or gets whether component's text can be edited by user typing. Applies to components such as TextField, TextArea, DocumentEditor, ComboBox, Password, Spinner, Tree (to edit list item).

Parameters:
NameTypeAttributesDescription
editableboolean<optional>

enables or disables editing

Returns:

If arguments is passed, returns this component instance, otherwise returns boolean value.

Type: 
Object | boolean

emit(event_name, event)

Emits a specified event with a custom event object for this component. This event will be sent to all event handlers registered with the specified event name.

Parameters:
NameTypeDescription
event_namestring

Name of the event is same as name of an event handler registering function, such as onAction or onChange.

eventobject

Custom event object

Example
button.emit("onAction", {type: "action", command: "Click Me"}); // emits a custom event without user clicking on the button

emitFocusKeyEvents(enableopt) → {this|boolean}

Enables/disables onKey() events to be emitted for focus traversal key (usually Tab key). By default onKey() event doesn't emit for such keys.

Parameters:
NameTypeAttributesDescription
enableboolean<optional>

true - enabled. false - disabled.

Returns:

Returns this component if argumen is provided, otherwise returns boolean value.

Type: 
this | boolean

enabled(enabledopt) → {boolean|this}

Sets or gets component enabled property.

Parameters:
NameTypeAttributesDescription
enabledboolean<optional>
Returns:

If value is provided, then this is returned, otherwise boolean value is returned.

Type: 
boolean | this

focusable(valueopt) → {boolean|this}

Sets or gets component focusable property whether component can retain focus.

Parameters:
NameTypeAttributesDescription
valueboolean<optional>
Returns:

If value is provided, then this is returned, otherwise boolean value is returned.

Type: 
boolean | this

focused(valueopt) → {boolean|this}

If value is provided, it makes component to get or loose focus, otherwise returns boolean indicating if it has focus or not.

Parameters:
NameTypeAttributesDescription
valueboolean<optional>

true to get focus, false to loose focus (if it has focus), usually by switching focus to next component.

Returns:

If value is provided, then this is returned, otherwise boolean value is returned.

Type: 
boolean | this

font(fontopt, updateopt) → {this|Object}

Gets or sets the font used for the component's text. See the example for font object format.

Parameters:
NameTypeAttributesDescription
fontObject<optional>

Font object.

updateboolean<optional>

If true, only the specified font properties will be updated instead of replacing the entire font.

Returns:
Type: 
this | Object
Examples
<h2>Full list of supported font properties:</h2>
const font = {
    name: string,           // Font family name (e.g., "sans-serif")
    size: number,           // Font size in pixels
    bold: boolean,          // Whether the text is bold
    italic: boolean,        // Whether the text is italic
    underlined: boolean,    // Whether the text is underlined
    strikethrough: boolean, // Whether the text has a strikethrough
    direction: string,      // Text direction: "ltr" or "rtl"
    kerning: boolean,       // Enable or disable kerning
    ligatures: boolean,     // Enable or disable font ligatures
    tracking: number        // Letter spacing adjustment: -1, 0 (default), or 1
};
<h2>Usage examples:</h2>
// Sets new font
textarea.font({name: "sans-serif", size: 14, italic: true});

// Set a new font; previously set italic style will be removed
textarea.font({name: "sans-serif", size: 14});

// Update only the font size, preserving other properties
textarea.font({size: 20}, true);

// get component's font
const font = textarea.font();

getAncestor(ancestor_class) → {Object|undefined}

Finds and returns first ancestor component of specified class. e.g. panel.getAncestor(Window) will return Window component that panel is in, or null if panel doesn't have a parent or ancestor with specified class.

Parameters:
NameTypeDescription
ancestor_classfunction

UI Component class that comes with swing-ui module.

Returns:
Type: 
Object | undefined

getWindow() → {Window|undefined}

Gets a top-most Window component containing this component.

Returns:

Returns a Window that contains this component, or undefined if no Window contain this component.

Type: 
Window | undefined

height(heightopt) → {number}

Convenience method to set or get the height of component.

Parameters:
NameTypeAttributesDescription
heightnumber<optional>
Returns:

Returns width if no argument is set, otherwise returns this component.

Type: 
number

hide() → {this}

Convenience function that calls this.visible(false)

Returns:
Type: 
this

icon(image_path) → {this|string|null}

Sets or gets an icon image of this component. You can set icon to any component even though not all components display the icon. When a component is added to Tabs and it has an icon, that icon will be used as a Tab icon by default.

Parameters:
NameTypeDescription
image_pathstring | null

Relative or absolute path to image file, base64 encoded image string, or NULL to remove existing icon.

Returns:

Returns this component if no arguments are set, string of an previously set icon, or null if icon hasn't been set.

Type: 
this | string | null

iconAlignment(alignmentopt) → {this|string}

Sets or gets an alignment of icon relative to text of a Label, Button, or items of a List.

Parameters:
NameTypeAttributesDescription
alignmentstring<optional>

A combination of one or more words: "top right bottom left center leading trailing"

Returns:

Returns this component if an argument is provided, otherwise returns string value.

Type: 
this | string

iconTextGap(gapopt) → {this|number}

Sets or get a gap in pixel between icon and text of a List item, Button, Label, ComboBox.

Parameters:
NameTypeAttributesDescription
gapnumber<optional>

The gap in pixels (must be an integer ≥ 0). If omitted, returns the current gap.

Returns:

Returns number if argument is omitted, otherwise returns this component instance.

Type: 
this | number

index(indexopt) → {this|null|number}

Sets of gets an index (z-order) of this component if it is added to a container, otherwise returns null. Larger value brings component forward, smaller to the back, like z-index in CSS.

Parameters:
NameTypeAttributesDescription
indexnumber<optional>
Returns:

If value is provided, then this component is returned, if component has no parent then null is returned, otherwise index is returned.

Type: 
this | null | number

indexOf(child) → {number}

Gets an index of a specified child component.

Parameters:
NameTypeDescription
childobject

A child of this component.

Returns:

Returns an index of a specified child component or -1 if the specified component is not a child fo this component.

Type: 
number

isInside(ancestor) → {boolean}

Checks if this component is inside of specified ancestor component (at any level, not just direct child).

Parameters:
NameTypeDescription
ancestorObject

Ancestor component to test against

Returns:
Type: 
boolean

layer(layer_index) → {number|this}

Sets or gets a layer at which this component resides in Panel container. This is separate from z-index. This applies only to components that are added to Panel or Window components. For example components in layer 2 are always on top of components in layer 1, regardless on their z-index. Larger value brings component forward, smaller to the back, like width z-index.

Parameters:
NameTypeDescription
layer_indexnumber
Returns:

If value is provided, then this is returned, otherwise number value is returned.

Type: 
number | this

maxIconSize(max_sizeopt) → {number|Object}

Gets or sets the maximum size of the icon's largest side (in pixels). If the icon's largest side is larger than the specified maximum, it will be scaled down proportionally. Applies to Button, Label, List, and ComboBox.

Parameters:
NameTypeAttributesDescription
max_sizenumber<optional>

Sets the maximum size of a larger side of icon.

Returns:

If called without arguments, returns number value, otherwise returns this component instance.

Type: 
number | Object

minIconSize(min_sizeopt) → {number|Object}

Gets or sets the minimum size of the icon's largest side (in pixels). If the icon's largest side is smaller than the specified minimum, it will be scaled up proportionally. Applies to Button, Label, List, and ComboBox.

Parameters:
NameTypeAttributesDescription
min_sizenumber<optional>

Sets the minimum size of a larger side of icon.

Returns:

If called without arguments, returns number value, otherwise returns this component instance.

Type: 
number | Object

move(dxopt, dyopt) → {this}

Moves the component by adding the specified x and y values to its current position. The function shifts the element's position relative to current position.

Parameters:
NameTypeAttributesDefaultDescription
dxnumber<optional>
0

Delta x (can be positive or negative number)

dynumber<optional>
0

Delta y (can be positive or negative number)

Returns:

Returns this component.

Type: 
this

onAction(callbackopt, removeopt) → {this|Array.<function()>}

Gets, registers or unregisters a handler function for component's primary action event. Some components don't have onAction events.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function that receives an event object. Pass null to unregister all handler functions.

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:

An array of handler functions if no arguments are passed, otherwise this component for method chaining.

Type: 
this | Array.<function()>
Example
// Example event object:
const e = {
  target: object,        // The component that triggered the event.
  command: string,       // Button text or a specified command using .command("") method
  modifiers: number,     // Keyboard modifiers (bitmask or flags).
  alt: boolean,          // Indicates if ALT key was pressed.
  shift: boolean,        // Indicates if SHIFT key was pressed.
  ctrl: boolean,         // Indicates if CTRL key was pressed.
  type: string,          // `action` or `index_change`. Present when applicable.
  x: number,             // Mouse x position relative to component
  y: number,             // Mouse y position relative to component
  screenX: number,       // Mouse x position relative to default screen
  screenY: number,       // Mouse y position relative to default screen
  interactive: boolean,  // Indicates if the action was triggered by user's interaction (not programmatically). Present when applicable.
  selected: false        // Present when applicable.
};

onAncestorEvents(callbackopt, removeopt) → {this|Array.<function()>}

Gets, registers or unregisters a handler function for component's event when ancestor is added, removed, or moved.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function that receives an event object. Pass null to unregister all handler functions.

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:

An array of handler functions if no arguments are passed, otherwise this component for method chaining.

Type: 
this | Array.<function()>
Example
// Example event object:
const e = {
  target: object,    // The component that triggered the event.
  type: string,      // `add`, `remove`, `move`.
  ancestor: object,  // The ancestor component.
};

onCaretEvents(callbackopt, removeopt) → {this|Array.<function()>}

Gets, registers or unregisters an event handler function for caret position changes and text selection changes in text editing components.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function that receives an event object. Pass null to unregister all handler functions.

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:

An array of handler functions if no arguments are passed, otherwise this component for method chaining.

Type: 
this | Array.<function()>
Example
// Example event object:
const e = {
  target: object,          // The component that triggered the event.
  type: string,            // `change`.
  position: number,        // New caret position
  selectionStart: number,  // Start position of selected text
  selectionEnd: number,    // End position of selected text
  line: number,            // Line of text where caret is now. Present only in some components, such as DocumentEditor.
  column: number,          // Position of caret from the beginning of the line where caret is now. Present only in multi-line text editing components, such as DocumentEditor.
  styles: object           // Text formatting information of the text segment where caret is now. Present only for DocumentEditor component when HTML is enabled.
  path: string[],          // HTML tag hierarchy. Present only for DocumentEditor component when HTML is enabled.
};

onChange(callbackopt, removeopt) → {this|Array.<function()>}

Gets, registers or unregisters a handler function for component's text value change event. Applied to components where text can be changed by user, such as TextField, PasswordField, TextArea, DocumentEditor, ComboBox, Spinner, etc.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function that receives an event object. Pass null to unregister all handler functions.

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:

An array of handler functions if no arguments are passed, otherwise this component for method chaining.

Type: 
this | Array.<function()>
Example
// Example event object:
const e = {
  target: object,   // The component that triggered the event.
  type: string,     // `change`, `changing`.
                    // change - when value has changed and there is no prediction that it is still being changed by user.
                    // changing - when the value is still being changed, for example Slider object's knob is still being moved by user. Present when applicable.
  action: string,   // `inserted`, `removed`. Present for some text editing components. Indicates an action performed with text.
  position: number, // Indicates position at which text was inserted. Present when e.action is present.
  length: number    // Indicates amount of characters inserted or removed. Present when e.action is present.
};

onComponentEvents(callbackopt, removeopt) → {this|Array.<function()>}

Gets, registers or unregisters an event handler function for events: resize, move, show, hide.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function that receives an event object. Pass null to unregister all handler functions.

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:

An array of handler functions if no arguments are passed, otherwise this component for method chaining.

Type: 
this | Array.<function()>
Example
// Example event object:
const e = {
 target: object,       // The component that triggered the event.
 type: string,         // `resize`, `move`, `show`, `hide`.
 interactive: boolean, // Indicates if the event was triggered by user's interaction (not programmatically). Present when e.type is `move` or `resize`.
 x: number,            // New x position of component.
 y: number,            // New y position of component.
 width: number,        // New width of component. Present when e.type is `resize`.
 height: number,       // New height of component. Present when e.type is `resize`.
 innerWidth: number,   // New width of content area of the component. Present when e.type is `resize` and component is Window or InternalWindow.
 innerHeight: number,  // New height of content area of the component. Present when e.type is `resize` and component is Window or InternalWindow.
};

onContainerEvents(callbackopt, removeopt) → {this|Array.<function()>}

Gets, registers or unregisters an event handler function for container-related events triggered when a child component is added or removed.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function that receives an event object. Pass null to unregister all handler functions.

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:

An array of handler functions if no arguments are passed, otherwise this component for method chaining.

Type: 
this | Array.<function()>
Example
// Example event object:
const e = {
  target: object,  // The container component that triggered the event.
  type: string,    // `add`, `remove`.
  child: object    // The child component that was added or removed
};

onDispose(callbackopt, removeopt) → {this}

Registers or unregisters a handler function for an event when the component gets disposed, either by calling destroy() method or loosing all references to the component.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function that receives an event object. Pass null to unregister all handler functions.

removeboolean<optional>
false

Set to true to remove this event handler

Returns:
Type: 
this

onDragEvents(callbackopt, removeopt) → {this|Array.<function()>}

Gets, registers or unregisters a handler function for drag related events.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function that receives an event object. Pass null to unregister all handler functions.

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:

An array of handler functions if no arguments are passed, otherwise this component for method chaining.

Type: 
this | Array.<function()>
Example
// Example event object:
const e = {
  target: object,         // The component that triggered the event.
  type: string,           // `dragstart`, `dragend`, `cancel`.
  action: string          // One of DragDropAction enum values. Present when applicable.
  x: number,              // X position of a pointer relative to this component. Present when e.type is `dragstart` or `dragend`.
  y: number,              // Y position of a pointer relative to this component. Present when e.type is `dragstart` or `dragend`.
  screenX: number,        // X position of a pointer relative to default screen. Present when e.type is `dragstart` or `dragend`.
  screenY: number,        // Y position of a pointer relative to default screen. Present when e.type is `dragstart` or `dragend`.
  button: number,         // Indicates a pointing device button involved in dragging. Value of MouseButton enum.
  modifiers: number,      // Keyboard modifiers (bitmask or flags). Present when e.type is `dragstart`.
  modifiersText: string,  // Keyboard modifiers. Present when e.type is `dragstart`.
  alt: boolean,           // Indicates if ALT key was pressed. Present when e.type is `dragstart`.
  shift: boolean,         // Indicates if SHIFT key was pressed. Present when e.type is `dragstart`.
  ctrl: boolean,          // Indicates if CTRL key was pressed. Present when e.type is `dragstart`.
  selected: number[]      // Array of selected indexes of a List component whose items are being dragged. Present when List items are being dragged.
};

onDropEvents(callbackopt, removeopt) → {this|Array.<function()>}

Gets, registers or unregisters a handler function for drop related events.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function that receives an event object. Pass null to unregister all handler functions.

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:

An array of handler functions if no arguments are passed, otherwise this component for method chaining.

Type: 
this | Array.<function()>
Example
// Example event object:
const e = {
  target: object,    // The component that triggered the event.
  type: string,      // `dragenter`, `dragover`, `dragleave`, `drop`.
  action: string     // One of the values of enum DragDropAction. Present when applicable.
  data: Object       // An object that contains the data that is being dropped. Present only when e.type is `drop` or `dragenter`.
  source: Object,    // A component that is being dragged or dropped onto this component.
                     // Present only when a another component is dragged onto this component and dragDataType() of dragged component was set to `Component`.
  x: number,         // X position of a pointer relative to this component. Present when e.type is `dragstart` or `drop`.
  y: number,         // Y position of a pointer relative to this component. Present when e.type is `dragstart` or `drop`.
  screenX: number,   // X position of a pointer relative to default screen. Present when e.type is `dragstart` or `drop`.
  screenY: number,   // Y position of a pointer relative to default screen. Present when e.type is `dragstart` or `drop`.
  selected: number[] // Array of selected indexes of a List component whose items are being dragged. Present when List items are being dragged.
};

onError(callbackopt) → {this}

Overrides current error handler.

Parameters:
NameTypeAttributesDescription
callbackfunction<optional>

The event handler function that receives an event object. Pass null to unregister all handler functions.

Returns:
Type: 
this

onFocusEvents(callbackopt, removeopt) → {this|Array.<function()>}

Gets, registers or unregisters a focus event handler function.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function that receives an event object. Pass null to unregister all handler functions.

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:

An array of handler functions if no arguments are passed, otherwise this component for method chaining.

Type: 
this | Array.<function()>
Example
// Example event object:
const e = {
  target: object,     // The component that triggered the event.
  type: string,       // `focus`, `blur`.
  cause: string       // `UNKNOWN`, `ACTIVATION`, `TRAVERSAL_FORWARD`, `TRAVERSAL_BACKWARD`.
  temporary: boolean, // Identifies the focus change event as temporary or permanent
};

onKey(callbackopt, removeopt) → {this|Array.<function()>}

Gets, registers or unregisters a keyboard keys' event handler function.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function that receives an event object. Pass null to unregister all handler functions.

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:

An array of handler functions if no arguments are passed, otherwise this component for method chaining.

Type: 
this | Array.<function()>
Example
// Example event object:
const e = {
  target: object,           // The component that triggered the event.
  type: string,             // `up`, `down`, `type`.
  keyCode: number           // Numeric code associated with the key
  extendedKeyCode: number   // The extended key code is a unique id assigned to a key on the keyboard just like keyCode. However, unlike keyCode, this value depends on the current keyboard layout.
  keyChar: string           // Key character
  modifiers: number,        // Keyboard modifiers (bitmask or flags).
  modifiersText: string     // Modifiers representation as a string.
  alt: boolean,             // Indicates if ALT key was pressed.
  shift: boolean,           // Indicates if SHIFT key was pressed.
  ctrl: boolean,            // Indicates if CTRL key was pressed.
  keyLocation: string       // `standard`, `numpad`, `left`, `right`. Location of the key on keyboard. Only present when type is `up` or `down`.
};

onMouseEvents(callbackopt, removeopt) → {this|Array.<function()>}

Gets, registers or unregisters a mouse buttons event handler function.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function that receives an event object. Pass null to unregister all handler functions.

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:

An array of handler functions if no arguments are passed, otherwise this component for method chaining.

Type: 
this | Array.<function()>
Example
// Example event object:
const e = {
  target: object,    // The component that triggered the event.
  type: string,      // `click`, `down`, `up`, `enter`, or `leave`.
  button: number,    // Button number. One of MouseButton enum values.
  clicks: number,    // Amount of time the click happened. Present when applicable.
  modifiers: number, // Keyboard modifiers (bitmask or flags).
  alt: boolean,      // Indicates if ALT key was pressed.
  shift: boolean,    // Indicates if SHIFT key was pressed.
  ctrl: boolean,     // Indicates if CTRL key was pressed.
  x: number,         // Present when applicable.
  y: number,         // Present when applicable.
  screenX: number,   // Present when applicable.
  screenY: number,   // Present when applicable.
};

onMouseMotion(callbackopt, removeopt) → {this|Array.<function()>}

Gets, registers or unregisters a mouse motion event handler function.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function that receives an event object. Pass null to unregister all handler functions.

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:

An array of handler functions if no arguments are passed, otherwise this component for method chaining.

Type: 
this | Array.<function()>
Example
// Example event object:
const e = {
  target: object,     // The component that triggered the event.
  type: string,       // `move` or `drag`.
  button: number,     // Button number. One of MouseButton enum values. Present when applicable.
  modifiers: number,  // Keyboard modifiers (bitmask or flags).
  x: number,          // Mouse x position relative to component
  y: number,          // Mouse y position relative to component
  screenX: number,    // Mouse x position relative to default screen
  screenY: number,    // Mouse y position relative to default screen
};

onMouseWheel(callbackopt, removeopt) → {this|Array.<function()>}

Gets, registers or unregisters a mouse wheel event handler function.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function that receives an event object. Pass null to unregister all handler functions.

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:

An array of handler functions if no arguments are passed, otherwise this component for method chaining.

Type: 
this | Array.<function()>
Example
// Example event object:
const e = {
  target: object,        // The component that triggered the event.
  type: string,          // `wheel`.
  button: number,        // Button number. One of MouseButton enum values. Present when applicable.
  scrollAmount: number,  // Returns the number of units that should be scrolled per click of mouse wheel rotation.
  rotation: number,      // Indicates the number of "clicks" the mouse wheel was rotated.
                         // A partial rotation may occur if the mouse supports a high-resolution wheel.
                         // In this case, the number is zero until a full "click" has been accumulated.
  modifiers: number,     // Keyboard modifiers (bitmask or flags).
  alt: boolean,          // Indicates if ALT key was pressed.
  shift: boolean,        // Indicates if SHIFT key was pressed.
  ctrl: boolean,         // Indicates if CTRL key was pressed.
  x: number,             // Mouse x position relative to component
  y: number,             // Mouse y position relative to component
  screenX: number,       // Mouse x position relative to default screen
  screenY: number,       // Mouse y position relative to default screen
};

onPropertyChange(callbackopt, removeopt) → {this|Array.<function()>}

Gets, registers or unregisters an event handler that listens for changes to this component's properties.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function that receives an event object. Pass null to unregister all handler functions.

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:

An array of handler functions if no arguments are passed, otherwise this component for method chaining.

Type: 
this | Array.<function()>
Example
// Example event object:
const e = {
  target: object,     // The container component that triggered the event.
  type: string,       // `change`.
  property: string,   // The property that was changed
  oldValue: any,      // Previous value of the changed property
  newValue: any       // New value of the changed property
};

onScroll(callbackopt, removeopt) → {this|Array.<function()>}

Gets, registers or unregisters an event handler function for scrolling of vertical and/or horizontal scroll bars. Applicable only to components with scroll bars.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function that receives an event object. Pass null to unregister all handler functions.

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:

An array of handler functions if no arguments are passed, otherwise this component for method chaining.

Type: 
this | Array.<function()>
Example
// Example event object:
const e = {
  target: object,  // The component that triggered the event.
  type: string,    // `horizontal`, `vertical`.
  x: number,       // New value of horizontal scroll position
  y: number,       // New value of vertical scroll position
  maxX: number,    // Maximum value of horizontal scroll position
  maxY: number     // Maximum value of vertical scroll position
};

opacity(opacityopt) → {number|this}

Sets or gets component opacity. Only valid for Window, Panel, and few more components.

Parameters:
NameTypeAttributesDescription
opacitynumber<optional>

A number between 0 and 1 inclusive.

Returns:

If opacity argument is provided, then this component is returned, otherwise opacity number is returned.

Type: 
number | this

paste() → {this}

Inserts clipboard text into component's text as current caret position. Applies only to some text editing components, such as TextArea.

Returns:

Returns this component

Type: 
this

position(x_or_positionopt, yopt, rightopt, bottomopt) → {Object|this}

Sets or gets the position of the component relative to its parent component (or to the screen, for a Window component).

Parameters:
NameTypeAttributesDescription
x_or_positionnumber | Object<optional>

X position. Alternatively, provide an object in the form {x: number, y: number} to specify the position (must be the only argument).

ynumber<optional>

Y position.

rightnumber<optional>

Resizes the component so that its right edge is this many pixels from the right edge of the parent component or screen.

bottomnumber<optional>

Resizes the component so that its bottom edge is this many pixels from the bottom edge of the parent component or screen.

Returns:

If no arguments are provided, returns a {x: number, y: number} position object. Otherwise, returns this component.

Type: 
Object | this
Example
panel.size(50, 100); // sets position
panel.size({x: 50, y: 100}); // sets position
panel.size(50, 100, 20); // sets position of left, top and right sides relative to sides of parent component.
const window = new Window("New Window").size(50, 100, 20, 20); // sets position of each side relative to sides of screen.

redo()

Attempts to perform redo operation and returns boolean specifying if redo operations can be performed on the text again. Only applies to components where text can be types (excluding Table cell editor).

Returns:

boolean

remove(recursiveopt) → {this}

Removes this component from its parent.

Parameters:
NameTypeAttributesDescription
recursiveboolean<optional>

Boolean indicates if all descendents of this child should also be removed.

Returns:

Returns this component for method chaining

Type: 
this
Example
child.remove(); // Removes child from it's parent container
child.remove(true); // Removes child component from it's parent and all its descendants recursively

removeChild(child_or_index, recursiveopt)

Removes component's child by child object or child index.

Parameters:
NameTypeAttributesDefaultDescription
child_or_indexobject | number

Child component object or index of the child.

recursiveboolean<optional>
false

Boolean indicates if all descendents of this child should also be removed.

Convenience method to get or set the distance between the right edge of this component and the right edge of its parent.

Parameters:
NameTypeAttributesDescription
valuenumber<optional>

Distance from the parent's right edge.

reizeboolean<optional>

True to resize the width to accommodate for specified right position instead of moving the object. false to move the component.

Returns:

Returns the current right distance if no argument is provided; otherwise, returns this component.

Type: 
number | this

scrollBarSize() → {Array.<number>|this}

Gets the size of scroll bars (horizontal and vertical). Setting is not supported yet.

Returns:

Returns a size Object {x:number, y:number} when arguments are omitted, otherwise this component instance.

Type: 
Array.<number> | this

scrollIncrement(pixels) → {this|number}

Sets or get scroll increment of a scrollable component.

Parameters:
NameTypeDescription
pixelsnumber

How many pixels the page is scrolled in one step of scrolling with up/down keys or mouse wheel.

Returns:

Returns this component if argument is provided, otherwise returns number value.

Type: 
this | number

scrollPosition(xopt, yopt) → {this|Object}

Sets and gets horizontal (X) and vertical (y) scroll positions. Applies only to components that have scroll bars, such as TextField, List, Table, DocumentEditor, Tree, ScrollPane, and InternalWindowContainer.

Parameters:
NameTypeAttributesDefaultDescription
xnumber<optional>
null

Set integer number to set horizontal position or null to omit. Omit this argument to get scroll position.

ynumber<optional>
null

Set integer number to set vertical position or null to omit.

Returns:

Returns horizontal and vertical scroll positions as an Object{x:number, y:number} if no arguments are passed, otherwise returns this component instance.

Type: 
this | Object
Example
const position = textarea.scrollPosition(); // Gets horizontal and vertical scroll positions as an Object{x:number, y:number}
textarea.scrollPosition(40, 20); // sets horizontal and vertical scroll positions
textarea.scrollPosition(null, 20); // sets only vertical scroll position
textarea.scrollPosition(40, null); // sets only horizontal scroll position
textarea.scrollPosition(40); // sets only horizontal scroll position

scrollbars(horizontal_or_bothopt, verticalopt) → {this|Object}

Sets or gets scroll bars visibility for horizontal and vertical scroll bars.

Parameters:
NameTypeAttributesDescription
horizontal_or_bothboolean | null | Object<optional>

true = visible, false = hidden, null = auto. Also can be an Object of both values. e.g. {h:false, v:null}

verticalboolean | null<optional>

true = visible, false = hidden, null = auto. When first argument is provided but this one is omitted, then this will match the first argument.

Returns:

Returns this component if at least one argument is provided, otherwise returns current state of both scroll bars: {h:boolean|null, v: boolean|null}.

Type: 
this | Object
Example
textarea.scrollbars(true); // makes both scroll bars always visible
textarea.scrollbars(false, null); // makes horizontal scroll bar hidden, but vertical will become visible as needed
textarea.scrollbars({h: false, v: null});  // makes horizontal scroll bar hidden, but vertical will become visible as needed

selectAll(selectedopt) → {this}

Selects all text of the component. Applies only to some text editing components, such as TextArea.

Parameters:
NameTypeAttributesDefaultDescription
selectedboolean<optional>
true

true to select all, false to deselect all.

Returns:

Returns this component

Type: 
this

selection(startopt, endopt) → {Object|this}

Gets selection description object or sets selection by providing start and end positions. For text editing component this selects and retrieves selected text. In list types of components (Table, List, Tree) this selects items or rows if multiple-selection is enabled.

Parameters:
NameTypeAttributesDescription
startnumber<optional>

Start position of selection.

endnumber<optional>

End position of selection. Requires if start argument is provided.

Returns:

Returns this component if arguments are provided, otherwise returns Object of format {start: number, end: number, text: string};

Type: 
Object | this

show() → {this}

Convenience function that calls this.visible(true)

Returns:
Type: 
this

size(width_or_sizeopt, heightopt) → {object}

Sets or gets the size of component.

Parameters:
NameTypeAttributesDescription
width_or_sizenumber | Object<optional>

Number as width, or object {width: number, height: number} as size object.

heightnumber<optional>

Height of component. Required if first argument is number.

Returns:

Component size object {width: number, height: number} if no arguments are set, otherwise returns this component.

Type: 
object
Example
// Usage examples:
button.size(100, 25);
button.size({width: 100, height: 25});
let size = button.size();

smoothScrolling(enable) → {this|number}

Sets or gets whether scrolling should be smooth (animated). Applies only to scrollable components.

Parameters:
NameTypeDescription
enableboolean

Enables or disables smooth scrolling

Returns:

Returns this component if argument is provided, otherwise returns boolean value.

Type: 
this | number

snapshot(formatopt, cropopt) → {string}

Captures an image of the component and all subcomponents. Returns the image as a base 64 encoded string in format "data:image/FORMAT;base64,As8fE4fdt1r.....".

Parameters:
NameTypeAttributesDefaultDescription
formatstring<optional>
"png"

Image format: png, jpg, jpeg, bmp, gif.

cropObject<optional>
null

Object that holds position and size of the cropped area. Format: {x: number, y: number, width: number, height: number}.

Returns:

Returns base 64 encoded string representation of the image. To get its binary data you must extract the base 64 string, then decode it from base 64 to bytes.

Type: 
string

text(textopt, actionopt, insert_positionopt) → {string|this}

Sets or gets text content of the component. Even though some components don't show text, you can still set text to it.

Parameters:
NameTypeAttributesDefaultDescription
textstring<optional>

Can be plain text or HTML. HTML is only supported in some components (e.g. Label, Button, TextDocument, ...) and should be surrounded with HTML tags. Check example below.

actionTextAction<optional>
TextAction.Set

Specific action to perform with text. Replace, append, prepend, or insert. Applies only to some components. Do not use this argument for HTML content.

insert_positionnumber<optional>

Position where to insert text. Applies only if action argument is TextAction.Insert.

Returns:

Returns text value if no argument is set, otherwise returns this component.

Type: 
string | this
Example
const txt = textfield.text(); // gets text value
textfield.text("New Text"); // sets new text value
textfield.text("Appended Text", TextAction.Append); // Appends new text to the end of current text
textfield.text("Inserted Text", TextAction.Insert); // Inserts at current caret position
textfield.text("Inserted Text", TextAction.Insert, textfield.caretPosition() - 50); // Inserts at specified position
textfield.text("New Text", TextAction.ReplaceSelection); // Replaces selected text or inserts at current cursor position if no text is selected (applies only to text editing components, like TextField, TextArea, ...).

tooltip(text) → {string|this}

Sets or gets tooltip text for the component. It's the text that pops up when cursor hovers the component.

Parameters:
NameTypeDescription
textstring

Can be plain text or HTML. HTML string should be surrounded with HTML tags. See example.

Returns:

Returns this component if argument is set, otherwise returns string value.

Type: 
string | this
Example
button.tooltip("<html>This is line 1<br />This is line 2</html>"); // Setting HTML string with 2 lines of text

undo()

Attempts to perform undo operation and returns boolean specifying if undo operations can be performed on the text again. Only applies to components where text can be types (excluding Table cell editor).

Returns:

boolean

undoEnabled(enable) → {this|boolean}

Sets or gets whether GUI should handle key combinations CTRL+Z and CTRL+Y to perform undo and redo actions for text editing components. If disabled, undo and redo can still be performed by calling undo() and redo() methods.

Parameters:
NameTypeDescription
enableboolean

Enables/disables undo/redo performed by keyboard keys. Default is true.

Returns:

Returns this component if argument is provided, otherwise returns boolean value.

Type: 
this | boolean

undoLimit(limitopt) → {this|number}

Sets or gets the maximum amount of edits that can be undone.

Parameters:
NameTypeAttributesDescription
limitnumber<optional>

Value 0 disabled undo/redo operation. Default is 100.

Returns:

Returns this component if argument is provided, otherwise returns number value.

Type: 
this | number

updateUI(pause_update) → {this}

Revalidates and repaints the component.

Parameters:
NameTypeDescription
pause_updateboolean

false to pause repainting this element. true to resume repainting

Returns:

Returns this component.

Type: 
this

verifyComponent() → {this}

This function may be called to make sure the component wasn't destroyed yet before performing another operation with the component. If it's already destroyed, Exception is thrown.

Returns:

Returns this component.

Type: 
this

visible(visibleopt) → {boolean|this}

Sets or gets component's visibility.

Parameters:
NameTypeAttributesDescription
visibleboolean<optional>
Returns:

If value is provided, then this is returned, otherwise boolean value is returned.

Type: 
boolean | this

width(widthopt) → {number}

Convenience method to set or get the width of component.

Parameters:
NameTypeAttributesDescription
widthnumber<optional>
Returns:

Returns height if no argument is set, otherwise returns this component.

Type: 
number

x(valueopt) → {number}

Convenience method to set or get left position of component.

Parameters:
NameTypeAttributesDescription
valuenumber<optional>
Returns:

Returns left position if no argument is set, otherwise returns this component.

Type: 
number

y(valueopt) → {number}

Convenience method to set or get top position of component.

Parameters:
NameTypeAttributesDescription
valuenumber<optional>
Returns:

Returns top position if no argument is set, otherwise returns this component.

Type: 
number

(static) get(id) → {any|undefined}

Get UI component by ID.

Parameters:
NameTypeDescription
idnumber

ID of requested component

Returns:

Returns UI component or undefined if there is no valid component with specified ID.

Type: 
any | undefined