Skip to Main Content
Java Swing, 2nd Edition
book

Java Swing, 2nd Edition

by Dave Wood, Robert Eckstein, Marc Loy, James Elliott, Brian Cole
November 2002
Intermediate to advanced content levelIntermediate to advanced
1278 pages
38h 26m
English
O'Reilly Media, Inc.
Content preview from Java Swing, 2nd Edition

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Threads, 3rd Edition

Java Threads, 3rd Edition

Scott Oaks, Henry Wong

Publisher Resources

ISBN: 0596004087Errata PageSupplemental Content