|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object![]()
![]()
![]()
java.awt.Component
![]()
![]()
![]()
java.awt.Container
![]()
![]()
![]()
javax.swing.JComponent
![]()
![]()
![]()
javax.swing.JLabel
, MenuContainer
, Serializable
, Accessible
, SwingConstants

, DefaultListCellRenderer
, DefaultTableCellRenderer
, DefaultTreeCellRenderer

public class JLabel

, Accessible

A display area for a short text string or an image, or both. A label does not react to input events. As a result, it cannot get the keyboard focus. A label can, however, display a keyboard alternative as a convenience for a nearby component that has a keyboard alternative but can't display it.
A JLabel object can display
either text, an image, or both.
You can specify where in the label's display area
the label's contents are aligned
by setting the vertical and horizontal alignment.
By default, labels are vertically centered
in their display area.
Text-only labels are leading edge aligned, by default;
image-only labels are horizontally centered, by default.
You can also specify the position of the text relative to the image. By default, text is on the trailing edge of the image, with the text and image vertically aligned.
A label's leading and trailing edge are determined from the value of its
ComponentOrientation
property. At present, the default
ComponentOrientation setting maps the leading edge to left and the trailing
edge to right.
Finally, you can use the setIconTextGap method
to specify how many pixels
should appear between the text and the image.
The default is 4 pixels.
See How to Use Labels in The Java Tutorial for further documentation.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans package.
Please see XMLEncoder
.
| Nested Class Summary | |
|---|---|
protected class |
JLabel.AccessibleJLabel
The class used to obtain the accessible role for this object. |
Nested classes/interfaces inherited from class javax.swing.JComponent ![]() |
|---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container ![]() |
|---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component ![]() |
|---|
Component.AccessibleAWTComponent |
| Field Summary | |
|---|---|
protected Component |
labelFor
|
Fields inherited from class javax.swing.JComponent ![]() |
|---|
accessibleContext |
Fields inherited from class java.awt.Component ![]() |
|---|
BOTTOM_ALIGNMENT |
Fields inherited from interface javax.swing.SwingConstants ![]() |
|---|
BOTTOM |
Fields inherited from interface java.awt.image.ImageObserver ![]() |
|---|
ABORT |
| Constructor Summary | |
|---|---|
JLabel
Creates a JLabel instance with
no image and with an empty string for the title. |
|
JLabel
Creates a JLabel instance with the specified image. |
|
JLabel
Creates a JLabel instance with the specified
image and horizontal alignment. |
|
JLabel
Creates a JLabel instance with the specified text. |
|
JLabel
Creates a JLabel instance with the specified
text, image, and horizontal alignment. |
|
JLabel
Creates a JLabel instance with the specified
text and horizontal alignment. |
|
| Method Summary | |
|---|---|
protected int |
checkHorizontalKey
Verify that key is a legal value for the horizontalAlignment properties. |
protected int |
checkVerticalKey
Verify that key is a legal value for the verticalAlignment or verticalTextPosition properties. |
AccessibleContext |
getAccessibleContext
Get the AccessibleContext of this object |
Icon |
getDisabledIcon
Returns the icon used by the label when it's disabled. |
int |
getDisplayedMnemonic
Return the keycode that indicates a mnemonic key. |
int |
getDisplayedMnemonicIndex
Returns the character, as an index, that the look and feel should provide decoration for as representing the mnemonic character. |
int |
getHorizontalAlignment
Returns the alignment of the label's contents along the X axis. |
int |
getHorizontalTextPosition
Returns the horizontal position of the label's text, relative to its image. |
Icon |
getIcon
Returns the graphic image (glyph, icon) that the label displays. |
int |
getIconTextGap
Returns the amount of space between the text and the icon displayed in this label. |
Component |
getLabelFor
Get the component this is labelling. |
String |
getText
Returns the text string that the label displays. |
LabelUI |
getUI
Returns the L&F object that renders this component. |
String |
getUIClassID
Returns a string that specifies the name of the l&f class that renders this component. |
int |
getVerticalAlignment
Returns the alignment of the label's contents along the Y axis. |
int |
getVerticalTextPosition
Returns the vertical position of the label's text, relative to its image. |
boolean |
imageUpdate
This is overridden to return false if the current Icon's Image is not equal to the passed in Image img. |
protected String |
paramString
Returns a string representation of this JLabel. |
void |
setDisabledIcon
Set the icon to be displayed if this JLabel is "disabled" (JLabel.setEnabled(false)). |
void |
setDisplayedMnemonic
Specifies the displayedMnemonic as a char value. |
void |
setDisplayedMnemonic
Specify a keycode that indicates a mnemonic key. |
void |
setDisplayedMnemonicIndex
Provides a hint to the look and feel as to which character in the text should be decorated to represent the mnemonic. |
void |
setHorizontalAlignment
Sets the alignment of the label's contents along the X axis. |
void |
setHorizontalTextPosition
Sets the horizontal position of the label's text, relative to its image. |
void |
setIcon
Defines the icon this component will display. |
void |
setIconTextGap
If both the icon and text properties are set, this property defines the space between them. |
void |
setLabelFor
Set the component this is labelling. |
void |
setText
Defines the single line of text this component will display. |
void |
setUI
Sets the L&F object that renders this component. |
void |
setVerticalAlignment
Sets the alignment of the label's contents along the Y axis. |
void |
setVerticalTextPosition
Sets the vertical position of the label's text, relative to its image. |
void |
updateUI
Resets the UI property to a value from the current look and feel. |
Methods inherited from class javax.swing.JComponent ![]() |
|---|
addAncestorListener |