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

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.