The ButtonModel Interface
The state of any Swing button is maintained by a ButtonModel object. This interface defines
methods for reading and writing a model’s properties and for adding and
removing various types of event listeners.
Properties
The properties for the ButtonModel interface are listed in Table 5-1. The actionCommand property specifies the name of the command to be sent
as part of the ActionEvent that is
fired when the button is pressed. This can be used by event handlers
that are listening to multiple buttons to determine which button is
pressed.
Table 5-1. ButtonModel properties
Property | Data type | get | is | set | Default value |
|---|---|---|---|---|---|
actionCommand | String | · | · | ||
armed | boolean | · | · | ||
enabled | boolean | · | · | ||
group | ButtonGroup | · | |||
mnemonic | int | · | · | ||
pressed | boolean | · | · | ||
rollover | boolean | · | · | ||
selected | boolean | · | · | ||
See also |
If no actionCommand
is specified, an ActionEvent takes the button’s text for its
command string, so it is usually not necessary to specify an explicit
actionCommand . You may find it useful to do so for buttons that have
icons but no text or for multiple buttons with the same text. actionCommand properties can also be handy
for internationalization. For example, if you need to change a
button’s text from "Hot" to
"Caliente", you won’t have to
change any event-handling code if you set the actionCommand to "Hot".
The group property refers to the ButtonGroup that contains the button (if
any). mnemonic contains the key that can be pressed in conjunction with a L&F-specific ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access