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

AbstractButton is an abstract base class for all button components (JButton, JToggleButton, JCheckBox, JRadioButton, and JMenuItem and its subclasses). Since it provides functionality common to all types of buttons, we’ll cover it here before getting to the concrete button classes.

AbstractButton provides much of the functionality associated with the interaction between the various concrete button classes and their ButtonModel objects. As we mentioned earlier, buttons in Swing can be made up of an image (Icon ), text, or both. The relative positions of the text and icon are specified exactly as they are with the JLabel class.

Image buttons may specify as many as seven different images, allowing the button to be displayed differently depending on its current state. The seven icons are described in Table 5-5, with the other properties defined by AbstractButton.

Properties

The AbstractButton class defines the properties shown in Table 5-5.

Table 5-5. AbstractButton properties

Property

Data type

get

is

set

Default value

action1.3

Action

·

 

·

null

actionCommand

String

·

 

·

null

borderPaintedb

boolean

 

·

·

true

contentAreaFilledb

boolean

 

·

·

true

disabledIconb

Icon

·

 

·

null

disabledSelectedIconb

Icon

·

 

·

null

displayedMnemonicIndex1.4

int

·

 

·

-1

enabledo

boolean

 

·

·

true

focusPaintedb

boolean

 

·

·

true

horizontalAlignmentb

int

·

 

·

CENTER

horizontalTextPositionb

int

·

 

·

TRAILING1.4

iconb

Icon

·

 

·

null

iconTextGap1.4

int

·

 

·

4

labeld

String

·

 

·

Same as text

marginb

Insets

·

 

·

null

mnemonicb

int

·

 

·

KeyEvent.VK_UNDEFINED ...

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