Generated Object
A javax.swing.JButton is returned, unless the user passes in a subclass of JButton as the value argument, in which case the value argument is returned.
Attributes
See also: JComponent
Declared in JButton
- defaultButton <boolean> Whether or not this button is the default button
- defaultCapable <boolean> Whether or not this button can be the default button
Declared in AbstractButton
- action <Action> the Action instance connected with this ActionEvent source
- actionCommand <String> actionCommand
- model <ButtonModel> Model that the Button uses.
- multiClickThreshhold <long> multiClickThreshhold
- selected <boolean> selected
Text related
- text <String> The button's text.
- label <String> Replace by setText(text)
- mnemonic <int> the keyboard character mnemonic
- displayedMnemonicIndex <int> the index into the String to draw the keyboard character mnemonic at
- horizontalTextPosition <int> The horizontal position of the text relative to the icon.
- verticalTextPosition <int> The vertical position of the text relative to the icon.
Rendering related
- borderPainted <boolean> Whether the border should be painted.
- contentAreaFilled <boolean> Whether the button should paint the content area or leave it transparent.
- focusPainted <boolean> Whether focus should be painted
- rolloverEnabled <boolean> Whether rollover effects should be enabled.
- margin <Insets> The space between the button's border and the label
- iconTextGap <int> If both the icon and text properties are set, this property defines the space between them.
Icon related
- icon <Icon> The button's default icon
- disabledIcon <Icon> The disabled icon for the button.
- pressedIcon <Icon> The pressed icon for the button.
- rolloverIcon <Icon> The rollover icon for the button.
- selectedIcon <Icon> The selected icon for the button.
- disabledSelectedIcon <Icon> The disabled selection icon for the button.
- rolloverSelectedIcon <Icon> The rollover selected icon for the button.
Alignment Related
- horizontalAlignment <int> The horizontal alignment of the icon and text.
- verticalAlignment <int> The vertical alignment of the icon and text.
Content
No child content is accepted in a button.
Usage
button creates a slider-bar type widget.
//TODO add an image
//TODO describe how to fire code on a button press
The selected property is not very interesting for the Button class, as it is not user changeable. This is mostly a leaky abstraction for checkBox and radioButton
Examples
This will run as a Groovy script.
| Code Block | ||
|---|---|---|
| ||
import groovy.swing.SwingBuilder
import java.awt.Insets
import javax.swing.JFrame
println 'hello, world'
new SwingBuilder().frame(title: 'demo using buttons', defaultCloseOperation: JFrame.EXIT_ON_CLOSE, show: true, pack: true) {
vbox() {
button(action: action(name: 'basic', closure: {println "basic"}))
button(action: action(name: 'mnemonic', mnemonic: 'P', closure: {println 'with mnemonic'}))
button(action: action(name: 'default', defaultButton: true, closure: {println 'this is the default button'}))
button(borderPainted:false, action: action(name: 'unpainted border', closure: {println 'unpainted border'}))
button(contentAreaFilled:false, action: action(name: 'unfilled content area', closure: {println 'unfilled content area'}))
button(focusPainted:false, action: action(name: 'unpainted focus (select it and you\'ll see)', closure: {println 'unpainted focus'}))
button(margin: new Insets(5, 10, 15, 20), action: action(name: 'margins', closure: {println 'margins'}))
}
}
|
//TBD further examples for icon related behaviour
Observable Attributes
- defaultCapable
- selected - via synthetic observation
- action
- borderPainted
- contentAreaFilled
- disabledIcon
- disabledSelectedIcon
- displayedMnemonicIndex
- focusPainted
- hideActionText
- horizontalAlignment
- horizontalTextPosition
- icon
- iconTextGap
- label
- margin
- mnemonic
- model
- pressedIcon
- rolloverEnabled
- rolloverIcon
- rolloverSelectedIcon
- selectedIcon
- text
- verticalAlignment
- verticalTextPosition