4.5 define actionbutton class
As shown in Figure 4-1, the AbstractButton class serves as an important Swing class behind the scenes as the Swing button component used. The JButton described in the JButton class later in this chapter is the simplest subclass. The remaining child classes will be described in subsequent sections.
All AbstractButton sub-classes use the ButtonModel interface to store data models. The DefaultButtonModel class is the default implementation used. In addition, we can combine any AbstractButton object into a ButtonGroup. Although this combination is the most natural for JRadioButton and JRadioButtonMenuItem components, any class actbutton will work.
4.5.1 role actbutton attributes
Table 4-11 lists the 32 attributes shared by the AbstractButton subclass. These attributes allow us to customize the appearance of all buttons.
Attribute name |
Data Type |
Accessibility |
Action |
Action |
Read/write binding |
ActionCommand |
String |
Read/write |
ActionListeners |
ActionListener [] |
Read-Only |
BorderPainted |
Boolean |
Read/write binding |
ChangeListeners |
ChangeListener [] |
Read-Only |
ContentAreaFilled |
Boolean |
Read/write binding |
DisabledIcon |
Icon |
Read/write binding |
DisabledSelectedIcon |
Icon |
Read/write binding |
DisabledMnemonicIndex |
Int |
Read/write binding |
Enabled |
Boolean |
Write only |
FocusPainted |
Boolean |
Read/write binding |
HorizontalAlignment |
Int |
Read/write binding |
HorizontalTextPosition |
Int |
Read/write binding |
Icon |
Icon |
Read/write binding |
IconTextGap |
Int |
Read/write binding |
ItemListeners |
ItemListener [] |
Read-Only |
Layout |
LayoutManager |
Write only |
Margin |
Insets |
Read/write binding |
Mnemonic |
Char |
Read/write binding |
Mnemonic |
Int |
Write only |
Model |
ButtonModel |
Read/write binding |
MultiClickThreshhold |
Long |
Read/write |
PressedIcon |
Icon |
Read/write binding |
Roloverenabled |
Boolean |
Read/write binding |
Rolow.con |
Icon |
Read/write binding |
Roloverselectedicon |
Icon |
Read/write binding |
Selected |
Boolean |
Read/write |
SelectedIcon |
Icon |
Read/write binding |
SelectedObjects |
Object [] |
Read-Only |
Text |
String |
Read/write binding |
UI |
ButtonUI |
Read/write |
VerticalAlignment |
Int |
Read/write binding |
VerticalTextPosition |
Int |
Read/write binding |
It is worth mentioning that multiClickThreshhold. This attribute indicates the time in milliseconds. If a button is selected multiple times during this interval, no additional action event is generated. By default, this property value is 0, meaning that an event is generated every time you click. To avoid repeated submission in important dialog boxes, set the value of this attribute to a value greater than 0.
ButtonModel/Class DefaultButtonModel Interface
The ButtonModel interface is used to describe the current status of the javasactbutton component. In addition, it describes a set of event listener objects supported by all different javasactbutton subclasses. It is defined as follows:
public interface ButtonModel extends ItemSelectable { // Properties public String getActionCommand(); public void setActionCommand(String newValue); public boolean isArmed(); public void setArmed(boolean newValue); public boolean isEnabled(); public void setEnabled(boolean newValue); public void setGroup(ButtonGroup newValue); public int getMnemonic(); public void setMnemonic(int newValue); public boolean isPressed(); public void setPressed(boolean newValue); public boolean isRollover(); public void setRollover(boolean newValue); public boolean isSelected(); public void setSelected(boolean newValue); // Listeners public void addActionListener(ActionListener listener);