Java Reference
In-Depth Information
Understanding AbstractButton Icons
AbstractButton has seven specific icon properties. The natural or default icon is the icon prop-
erty. It is used for all cases unless a different icon is specified or there is a default behavior
provided by the component. The selectedIcon property is the icon used when the button is
selected. The pressedIcon is used when the button is pressed. Which of these two icons is used
depends on the component, because a JButton is pressed but not selected, whereas a
JCheckBox is selected but not pressed.
The disabledIcon and disabledSelectedIcon properties are used when the button has
been disabled with setEnabled(false) . By default, if the icon is an ImageIcon , a grayscaled
version of the icon will be used.
The remaining two icon properties, rolloverIcon and rolloverSelectedIcon , allow you to
display different icons when the mouse moves over the button (and rolloverEnabled is true ).
Understanding Internal AbstractButton Positioning
The horizontalAlignment , horizontalTextPosition , verticalAlignment , and
verticalTextPosition properties share the same settings and behavior as the JLabel class.
They're listed in Table 4-13.
Table 4-13. AbstractButton Position Constants
Position Property
Available Settings
horizontalAlignment
LEFT , CENTER , RIGHT
horizontalTextPosition
LEFT , CENTER , RIGHT
verticalAlignment
TOP , CENTER , BOTTOM
verticalTextPosition
TOP , CENTER , BOTTOM
Handling AbstractButton Events
Although you do not create AbstractButton instances directly, you do create subclasses.
All of them share a common set of event-handling capabilities. You can register
PropertyChangeListener , ActionListener , ItemListener , and ChangeListener objects with
abstract buttons. The PropertyChangeListener object will be discussed here, and the
remaining objects listed will be discussed in later chapters, with the appropriate components.
Like the JComponent class, the AbstractButton component supports the registering of
PropertyChangeListener objects to detect when bound properties of an instance of the class
change. Unlike the JComponent class, the AbstractButton component provides the following set
of class constants to signify the different property changes:
• BORDER_PAINTED_CHANGED_PROPERTY
• CONTENT_AREA_FILLED_CHANGED_PROPERTY
• DISABLED_ICON_CHANGED_PROPERTY
• DISABLED_SELECTED_ICON_CHANGED_PROPERTY
• FOCUS_PAINTED_CHANGED_PROPERTY
Search WWH ::




Custom Search