Button
Component Palette Icon
The Button component is a versatile component, often used for things like opening/closing windows, writing to tags, and triggering any sort of scripting logic. It can be used for showing status, as well. For example, if you have three buttons, Hand, Off, and Auto, not only can they set those modes, but their background color can display the current mode, although you'd be better off using the Multi-State Button for this.
To get buttons to do things, you add an event handler to the actionPerformed event. While you could configure your script on a mousePressed or mouseClicked event handlers, it is better to use the actionPerformed event as buttons can be activated by tabbing over to them and hitting the space key, or by pressing Alt and the button's mnemonic character. So, to make sure that your button works in all of these cases, configure your event handler on the actionPerformed event, not the mouseClicked event.
Properties
Name | Description | Property Type | Scripting | Category |
---|---|---|---|---|
Antialias | Draw with antialias on? Makes text smoother. | boolean | .antialias | Appearance |
Background 3D? | Should this button have a 3d type background, or a flat color one? | boolean | .background3D | Appearance |
Background Color | The background color of the button. | Color | .buttonBG | Appearance |
Border | The border surrounding this component. NOTE that the border is unaffected by rotation. | Border | .border | Common |
Border Painted? | Should the border of this button be displayed? | boolean | .borderPainted | Appearance |
Cursor | The mouse cursor to use when hovering over this component. | int | .cursorCode | Common |
Data Quality | The data quality code for any tag bindings on this component. | int | .dataQuality | Data |
Default Button | If true, this button will be activated when the user presses enter on the window. | boolean | .defaultBtn | Behavior |
Disabled Image Path | The relative path of the image to be displayed when this component is not enabled. | String | .disabledPath | Appearance |
Enabled | If disabled, a component cannot be used. | boolean | .componentEnabled | Common |
Fill Area? | Controls whether or not this button's internal area is filled. | boolean | .contentAreaFilled | Appearance |
Focusable | If a button is not focusable, you will not be able to interact with it with the keyboard. This means you can't "tab" over to it. | boolean | .focusable | Behavior |
Font | Font of text on this component. | Font | .font | Appearance |
Foreground Color | The foreground color of the component. | Color | .foreground | Appearance |
Horizontal Alignment | The horizontal alignment of the button's contents (text and/or image). | int | .horizontalAlignment | Layout |
Horizontal Text Position | The horizontal position of the button's text relative to its image. | int | .horizontalTextPosition | Layout |
Icon-Text Spacing | The space (in pixels) between the icon (if any) and the text (if any). | int | .iconTextGap | Appearance |
Image Path | The relative path of the image. | String | .path | Appearance |
Margin | The space between a button's text and its borders. | Insets | .margin | Layout |
Mnemonic | A single letter that will activate the button using 'ALT-mnemonic'. | String | .mnemonicChar | Behavior |
Mouseover Text | The text that is displayed in the tooltip which pops up on mouseover of this component. | String | .toolTipText | Common |
Name | The name of this component. | String | .name | Common |
Opaque | Is this button completely opaque? Most aren't, so this should usually be false. | boolean | .opaque | Common |
Rollover | If true, the button may indicate that the mouse is hovering over it. | boolean | .rolloverEnabled | Behavior |
Styles | Contains the component's styles. | Dataset | .styles | Appearance |
Text | Text of this component. | String | .text | Appearance |
Vertical Alignment | The vertical alignment of the button's contents (text and/or image). | int | .verticalAlignment | Layout |
Vertical Text Position | The vertical position of the button's text relative to its image. | int | .verticalTextPosition | Layout |
Visible | If disabled, the component will be hidden. | boolean | .visible | Common |
Scripting
Scripting Functions
.doClick()
- Description
Virtually "clicks" the button, meaning that its actionPerformed event handler will run. - Parameters
Nothing - Return
Nothing - Scope
Client
Extension Functions
This component does not have extension functions associated with it.
Event Handlers
Event handlers allow you to run a script based off specific triggers. See the full list of available event handlers on the Component Events page
Customizers
Styled Button Examples
Property Name | Value |
---|---|
Border | Etched |
Font | Dialog, Bold, 18 |
Text | Press Me! |
Image Path | Builtin/icons/48/check2.png |
Property Name | Value |
---|---|
Border | No Border |
Fill Area? | False |
Border Painted? | False |
Text | None |
Image Path | Builtin/icons/48/stop.png |