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

actionCommand o

String

·

 

·

null

armed o

boolean

 

·

·

false

enabled o

boolean

 

·

·

true

group o, *

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: ...

Get Java Swing, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.