The JToggleButton.ToggleButtonModel Class

As we mentioned earlier, JToggleButton does not use the DefaultButtonModel class as its model. ToggleButtonModel, a public static inner class that extends DefaultButtonModel, is used instead.

Properties

ToggleButtonModel modifies the methods for working with the properties listed in Table 5-11. New implementations of isSelected( ) and setSelected( ) use the button’s ButtonGroup (if defined) to keep track of which button is selected, ensuring that even if multiple selected buttons are added to a group, only the first one is considered selected (since the group keeps track of the “officially” selected button). In addition, the setPressed( ) method is redefined to call setSelected( ) when the button is released (if it is armed)

Table 5-11. JToggleButton.ToggleButtonModel properties

Property

Data type

get

is

set

Default value

pressedo

boolean

 

·

·

false

selectedo

boolean

 

·

·

false

ooverridden

See also properties from DefaultButtonModel (Table 5-3).

     

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.