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 JButton Class

JButton is the simplest of the button types, adding very little to what is provided by the AbstractButton class. JButtons are buttons that are not toggled on and off but instead act as push buttons, which invoke some action when clicked. Figure 5-2 shows what these buttons look like in four of the Swing L&Fs.

JButtons in four L&Fs

Figure 5-2. JButtons in four L&Fs

Properties

The JButton class inherits most of its properties and default values from its superclasses. The exceptions to this are shown in Table 5-9. The model property is set to a new instance of DefaultButtonModel when a JButton is created.

Table 5-9. JButton properties

Property

Data type

get

is

set

Default value

accessibleContexto

AccessibleContext

·

  

JButton.AccessibleJButton( )

defaultButton

boolean

 

·

 

false

defaultCapable

boolean

 

·

·

true

modelo

ButtonModel

·

 

·

DefaultButtonModel( )

UIClassIDo

String

·

  

“ButtonUI”

ooverridden

See also properties from AbstractButton (Table 5-5).

     

The defaultButton property indicates whether the button is activated by default when some event occurs within the JRootPane containing the button. Typically, the event that would trigger the button would be an Enter key press, but this is actually up to the L&F implementation.

The defaultButton property cannot be set directly. Instead, it is set by telling the JRootPane which button should be the default. (We’ll cover JRootPane in Chapter 8—at this point, it’s enough ...

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