Overview | Package | Class | Tree | Deprecated | Index | Help |
Java Platform 1.1.7 |
||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--com.sun.java.swing.JComponent | +--com.sun.java.swing.JLabel
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 left-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 to the right of the image, with the text and image vertically aligned.
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 Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.
Inner Class Summary | |
JLabel.AccessibleJLabel
The class used to obtain the accessible role for this object. |
Inner classes inherited from class com.sun.java.swing.JComponent | |
JComponent.AccessibleJComponent |
Field Summary | |
java.awt.Component | labelFor
--- Accessibility Support --- |
Fields inherited from class com.sun.java.swing.JComponent | |
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component | |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Constructor Summary | |
JLabel(java.lang.String text,
Icon icon,
int horizontalAlignment)
Creates a JLabel instance with the specified
text, image, and horizontal alignment.
|
|
JLabel(java.lang.String text,
int horizontalAlignment)
Creates a JLabel instance with the specified
text and horizontal alignment.
|
|
JLabel(java.lang.String text)
Creates a JLabel instance with the specified text.
|
|
JLabel(Icon image,
int horizontalAlignment)
Creates a JLabel instance with the specified
image and horizontal alignment.
|
|
JLabel(Icon image)
Creates a JLabel instance with the specified image.
|
|
JLabel()
Creates a JLabel instance with
no image and with an empty string for the title.
|
Method Summary | |
int | checkHorizontalKey(int key,
java.lang.String message)
Verify that key is a legal value for the horizontalAlignment or horizontalTextPosition properties. |
int | checkVerticalKey(int key,
java.lang.String message)
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 value of the disabledIcon property if it's been set, If it hasn't been set and the value of the icon property is an ImageIcon, we compute a "grayed out" version of the icon and update the disabledIcon property with that. |
int | getDisplayedMnemonic()
Return the keycode that indicates a mnemonic key. |
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. |
java.awt.Component | getLabelFor()
Get the component this is labelling. |
java.lang.String | getText()
Returns the text string that the label displays. |
java.lang.String | getUIClassID()
Returns a string that specifies the name of the l&f class that renders this component. |
com.sun.java.swing.plaf.LabelUI | getUI()
Returns the L&F object 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. |
void | setDisabledIcon(Icon disabledIcon)
Set the icon to be displayed if this JLabel is "disabled", i.e. |
void | setDisplayedMnemonic(int key)
Specify a keycode that indicates a mnemonic key. |
void | setDisplayedMnemonic(char aChar)
|
void | setFont(java.awt.Font font)
Sets the font used to display the label's text. |
void | setHorizontalAlignment(int alignment)
Sets the alignment of the label's contents along the X axis. |
void | setHorizontalTextPosition(int x)
Sets the horizontal position of the label's text, relative to its image. |
void | setIcon(Icon icon)
Defines the icon this component will display. |
void | setIconTextGap(int iconTextGap)
If both the icon and text properties are set, this property defines the space between them. |
void | setLabelFor(java.awt.Component c)
Set the component this is labelling. |
void | setText(java.lang.String text)
Defines the single line of text this component will display. |
void | setUI(com.sun.java.swing.plaf.LabelUI ui)
Sets the L&F object that renders this component. |
void | setVerticalAlignment(int alignment)
Sets the alignment of the label's contents along the Y axis. |
void | setVerticalTextPosition(int textPosition)
Sets the vertical position of the label's text, relative to its image. |
void | updateUI()
Notification from the UIFactory that the L&F has changed. |
Methods inherited from class java.awt.Container | |
add, add, add, add, add, addContainerListener, addImpl, addNotify, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponentAt, getComponentAt, getComponent, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, paint, paramString, preferredSize, printComponents, print, processContainerEvent, processEvent, removeAll, remove, remove, removeContainerListener, removeNotify, setLayout, update, validate, validateTree |
Methods inherited from class java.awt.Component | |
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paint, paramString, postEvent, preferredSize, prepareImage, prepareImage, printAll, print, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate |
Methods inherited from class java.lang.Object | |
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait |
Field Detail |
protected java.awt.Component labelFor
Constructor Detail |
public JLabel(java.lang.String text, Icon icon, int horizontalAlignment)
JLabel
instance with the specified
text, image, and horizontal alignment.
The label is centered vertically in its display area.
The text is to the right of the image.
text
- The text to be displayed by the label.
icon
- The image to be displayed by the label.
horizontalAlignment
- One of the following constants
defined in SwingConstants
:
LEFT
,
CENTER
, or
RIGHT
.public JLabel(java.lang.String text, int horizontalAlignment)
JLabel
instance with the specified
text and horizontal alignment.
The label is centered vertically in its display area.
text
- The text to be displayed by the label.
horizontalAlignment
- One of the following constants
defined in SwingConstants
:
LEFT
,
CENTER
, or
RIGHT
.public JLabel(java.lang.String text)
JLabel
instance with the specified text.
The label is aligned against the left side of its display area,
and centered vertically.
text
- The text to be displayed by the label.public JLabel(Icon image, int horizontalAlignment)
JLabel
instance with the specified
image and horizontal alignment.
The label is centered vertically in its display area.
icon
- The image to be displayed by the label.
horizontalAlignment
- One of the following constants
defined in SwingConstants
:
LEFT
,
CENTER
, or
RIGHT
.public JLabel(Icon image)
JLabel
instance with the specified image.
The label is centered vertically and horizontally
in its display area.
icon
- The image to be displayed by the label.public JLabel()
JLabel
instance with
no image and with an empty string for the title.
The label is centered vertically
in its display area.
The label's contents, once set, will be displayed at the left
of the label's display area.Method Detail |
public com.sun.java.swing.plaf.LabelUI getUI()
public void setUI(com.sun.java.swing.plaf.LabelUI ui)
ui
- the LabelUI L&F objectpublic void updateUI()
public java.lang.String getUIClassID()
public java.lang.String getText()
public void setText(java.lang.String text)
The default value of this property is null.
This is a JavaBeans bound property.
public Icon getIcon()
public void setIcon(Icon icon)
The default value of this property is null.
This is a JavaBeans bound property.
public Icon getDisabledIcon()
public void setDisabledIcon(Icon disabledIcon)
The default value of this property is null.
disabledIcon
- the Icon to display when the component is disabledpublic void setDisplayedMnemonic(int key)
public void setDisplayedMnemonic(char aChar)
public int getDisplayedMnemonic()
protected int checkHorizontalKey(int key, java.lang.String message)
key
- the property value to check
message
- the IllegalArgumentException detail messageprotected int checkVerticalKey(int key, java.lang.String message)
key
- the property value to check
message
- the IllegalArgumentException detail messagepublic int getIconTextGap()
public void setIconTextGap(int iconTextGap)
The default value of this property is 4 pixels.
This is a JavaBeans bound property.
public int getVerticalAlignment()
SwingConstants
:
TOP
,
CENTER
, or
BOTTOM
.public void setVerticalAlignment(int alignment)
The default value of this property is CENTER.
This is a JavaBeans bound property.
alignment
- One of the following constants
defined in SwingConstants
:
TOP
,
CENTER
(the default), or
BOTTOM
.public int getHorizontalAlignment()
SwingConstants
:
LEFT
,
CENTER
, or
RIGHT
.public void setHorizontalAlignment(int alignment)
This is a JavaBeans bound property.
alignment
- One of the following constants
defined in SwingConstants
:
LEFT
(the default for text-only labels),
CENTER
(the default for image-only labels), or
RIGHT
.public int getVerticalTextPosition()
SwingConstants
:
TOP
,
CENTER
, or
BOTTOM
.public void setVerticalTextPosition(int textPosition)
The default value of this property is CENTER.
This is a JavaBeans bound property.
textPosition
- One of the following constants
defined in SwingConstants
:
TOP
,
CENTER
(the default), or
BOTTOM
.public int getHorizontalTextPosition()
SwingConstants
:
LEFT
,
CENTER
, or
RIGHT
.public void setHorizontalTextPosition(int x)
x
- One of the following constants
defined in SwingConstants
:
LEFT
,
CENTER
, or
RIGHT
(the default).public void setFont(java.awt.Font font)
font
- The font to use.public AccessibleContext getAccessibleContext()
public java.awt.Component getLabelFor()
public void setLabelFor(java.awt.Component c)
c
- the Component this label is for, or null if the label is
not the label for a componentOverview | Package | Class | Tree | Deprecated | Index | Help |
Java Platform 1.1.7 |
||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |