O'Reilly logo

Java Swing, 2nd Edition by Brian Cole, James Elliott, Marc Loy, Robert Eckstein, Dave Wood

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 JToggleButtons 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).

JToggleButtons in four L&Fs

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 AbstractButton (Table 5-5).

     

Events

Like JButton, JToggleButton defines no new events. However, the events fired by JToggleButtons are slightly different than those fired by

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required