The DefaultButtonModel Class
Swing provides an implementation of the ButtonModel interface called DefaultButtonModel.
This class is used directly by the AbstractButton class and indirectly by the
other button classes. JToggleButton
defines an inner class extending DefaultButtonModel that it and its descendants
use to manage their state data.
Properties
The DefaultButtonModel class
gets most of its properties from ButtonModel. The default values set by this
class are shown in Table
5-3.
Table 5-3. DefaultButtonModel properties
Property | Data type | get | is | set | Default value |
|---|---|---|---|---|---|
| String | · | · | null | |
| boolean | · | · | false | |
| boolean | · | · | true | |
| ButtonGroup | · | · | null | |
mnemonico | int | · | · | KeyEvent.VK_UNDEFINED | |
pressedo | boolean | · | · | false | |
rollovero | boolean | · | · | false | |
selectedo | boolean | · | · | false | |
selectedObjects | Object[] | · | null | ||
ooverridden, *getter was introduced in SDK 1.3 |
The only property here that does not come from the ButtonModel interface is the selectedObjects property. DefaultButtonModel provides a getSelectedObjects( ) method because it is
mandated by the ItemSelectable
interface, but it always returns null. SDK 1.3 added the getGroup( ) method.
Events
The events fired by DefaultButtonModel are those required by
ButtonModel and listed in Table 5-2. An ActionEvent is fired when the button is
pressed, an ItemEvent is fired when
the button’s state is changed, and a ChangeEvent is fired when a change has
occurred to the button’s properties.
This class implements the following standard methods: ...
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