The JToggleButton Class
JToggleButton
is an extension of AbstractButton
and is used to represent
buttons that can be toggled on and off (as opposed to buttons like
JButton
which, when pushed, “pop back
up”). It should be noted that while the subclasses of JToggleButton
(JCheckBox
and JRadioButton
) are the kinds of JToggleButton
s most commonly used, JToggleButton
is not an abstract class. When
used directly, it typically (though this is ultimately up to the
L&F) has the appearance of a JButton
that does not pop back up when pressed
(see Figure 5-6).
Figure 5-6. JToggleButtons in four L&Fs
Properties
The JToggleButton
class
inherits all of its properties and most of its default values from its
superclass. The exceptions are shown in Table 5-10. The model
property is set to a new instance of
ToggleButtonModel
when a JToggleButton
is created. ToggleButtonModel
(described in the next
section) is a public inner class that extends DefaultButtonModel
.
Table 5-10. JToggleButton properties
Property | Data type | get | is | set | Default value |
---|---|---|---|---|---|
accessibleContexto | AccessibleContext | · | JToggleButton.AccessibleJToggleButton( ) | ||
modelo | ButtonModel | · | · | ToggleButtonModel( ) | |
UIClassIDo | String | · | “ToggleButtonUI” | ||
ooverridden See also properties from |
Events
Like JButton
, JToggleButton
defines no new events. However, the events fired by
JToggleButton
s are slightly
different than those fired by
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.