All Packages Class Hierarchy This Package Previous Next Index
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.
Every time you change the display characteristics of a label, it repaints itself. [SHOULD THIS GO WITHOUT SAYING?]
JLabel
instance with
no image and with an empty string for the title.
JLabel
instance with the specified image.
JLabel
instance with the specified
image and horizontal alignment.
JLabel
instance with the specified text.
JLabel
instance with the specified
text, image, and horizontal alignment.
JLabel
instance with the specified
text and horizontal alignment.
protected static String fallbackUI
public JLabel(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.
GraphicsUtilsConstants
:
LEFT
,
CENTER
, or
RIGHT
.
public JLabel(String text, int horizontalAlignment)
JLabel
instance with the specified
text and horizontal alignment.
The label is centered vertically in its display area.
GraphicsUtilsConstants
:
LEFT
,
CENTER
, or
RIGHT
.
public JLabel(String text)
JLabel
instance with the specified text.
The label is aligned against the left side of its display area,
and centered vertically.
public JLabel(Icon image, int horizontalAlignment)
JLabel
instance with the specified
image and horizontal alignment.
The label is centered vertically in its display area.
GraphicsUtilsConstants
:
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.
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.
public LabelUI getUI()
public void setUI(LabelUI ui)
public void updateUI()
public String getText()
public void setText(String text)
public Icon getIcon()
public void setIcon(Icon g)
public void setRepresentedKeyAccelerator(char aKey)
public char getRepresentedKeyAccelerator()
public Icon getDisabledIcon()
public void setDisabledIcon(Icon g)
protected int checkHorizontalKey(int x, String s)
protected int checkVerticalKey(int x, String s)
public void setIconTextGap(int n)
public int getIconTextGap()
public int getVerticalAlignment()
GraphicsUtilsConstants
:
TOP
,
CENTER
, or
BOTTOM
.
public void setVerticalAlignment(int x)
GraphicsUtilsConstants
:
TOP
,
CENTER
(the default), or
BOTTOM
.
public int getHorizontalAlignment()
GraphicsUtilsConstants
:
LEFT
,
CENTER
, or
RIGHT
.
public void setHorizontalAlignment(int x)
GraphicsUtilsConstants
:
LEFT
(the default for text-only labels),
CENTER
(the default for image-only labels), or
RIGHT
.
public int getVerticalTextPosition()
GraphicsUtilsConstants
:
TOP
,
CENTER
, or
BOTTOM
.
public void setVerticalTextPosition(int x)
GraphicsUtilsConstants
:
TOP
,
CENTER
(the default), or
BOTTOM
.
public int getHorizontalTextPosition()
GraphicsUtilsConstants
:
LEFT
,
CENTER
, or
RIGHT
.
public void setHorizontalTextPosition(int x)
GraphicsUtilsConstants
:
LEFT
,
CENTER
, or
RIGHT
(the default).
public void setFont(Font x)
All Packages Class Hierarchy This Package Previous Next Index