Java Reference
In-Depth Information
The
displayedMnemonicIndex
property adds the ability for the mnemonic highlighted to
not be the first instance of mnemonic in the label's text. The index you specify represents the
position in the text, not the instance of the mnemonic. To highlight the second
e
in Username,
you would specify an index of 7:
label.setDisplayedMnemonicIndex(7)
.
■
Note
The component setting of the
labelFor
property is stored as a client property of the
JLabel
with
the
LABELED_BY_PROPERTY
key constant. The setting is used for accessibility purposes.
Customizing a JLabel Look and Feel
Each installable Swing look and feel provides a different
JLabel
appearance and set of default
UIResource
value settings. Although appearances differ based on the current look and feel, the
differences are minimal within the preinstalled set of look and feel types. Table 4-9 shows the
available set of
UIResource
-related properties for a
JLabel
. There are eight different properties
for the
JLabel
component.
Table 4-9.
JLabel UIResource Elements
Property String
Object Type
Label.actionMap
ActionMap
Label.background
Color
Label.border
Border
Label.disabledForeground
Color
Label.disabledShadow
Color
Label.font
Font
Label.foreground
Color
LabelUI
String
Interface Icon
The
Icon
interface is used to associate glyphs with various components. A
glyph
(like a symbol
on a highway sign that conveys information nonverbally, such as “winding road ahead!”) can
be a simple drawing or a GIF image loaded from disk with the
ImageIcon
class. The interface
contains two properties describing the size and a method to paint the glyph.
public interface Icon {
// Properties
public int getIconHeight();
public int getIconWidth();
// Other methods
public void paintIcon(Component c, Graphics g, int x, int y);
}