All Packages Class Hierarchy This Package Previous Next Index
Class com.sun.java.swing.JLabel
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----com.sun.java.swing.JComponent
|
+----com.sun.java.swing.JLabel
- public class JLabel
- extends JComponent
- implements SwingConstants, 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 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?]
-
fallbackUI
-
-
labelFor
-
-
JLabel()
- Creates a
JLabel
instance with
no image and with an empty string for the title.
-
JLabel(Icon)
- Creates a
JLabel
instance with the specified image.
-
JLabel(Icon, int)
- Creates a
JLabel
instance with the specified
image and horizontal alignment.
-
JLabel(String)
- Creates a
JLabel
instance with the specified text.
-
JLabel(String, Icon, int)
- Creates a
JLabel
instance with the specified
text, image, and horizontal alignment.
-
JLabel(String, int)
- Creates a
JLabel
instance with the specified
text and horizontal alignment.
-
checkHorizontalKey(int, String)
-
-
checkVerticalKey(int, String)
-
-
getAccessibleName()
- Get the accessible name of this object.
-
getAccessibleRole()
- Get the role of this object.
-
getDisabledIcon()
-
-
getHorizontalAlignment()
- Returns the alignment of the label's contents along the X axis.
-
getHorizontalTextPosition()
- Returns the horizontal position of the label's text,
relative to its image.
-
getIcon()
-
-
getIconTextGap()
-
-
getLabelFor()
- Get the component this is labelling.
-
getRepresentedKeyAccelerator()
-
-
getText()
-
-
getUI()
-
-
getVerticalAlignment()
- Returns the alignment of the label's contents along the Y axis.
-
getVerticalTextPosition()
- Returns the vertical position of the label's text,
relative to its image.
-
setDisabledIcon(Icon)
-
-
setFont(Font)
- Sets the font used to display the label's text.
-
setHorizontalAlignment(int)
- Sets the alignment of the label's contents along the X axis.
-
setHorizontalTextPosition(int)
- Sets the horizontal position of the label's text,
relative to its image.
-
setIcon(Icon)
-
-
setIconTextGap(int)
-
-
setLabelFor(Component)
- Set the component this is labelling.
-
setRepresentedKeyAccelerator(char)
-
-
setText(String)
-
-
setUI(LabelUI)
-
-
setVerticalAlignment(int)
- Sets the alignment of the label's contents along the Y axis.
-
setVerticalTextPosition(int)
- Sets the vertical position of the label's text,
relative to its image.
-
updateUI()
- Notification from the UIFactory that the L&F
has changed.
fallbackUI
protected static String fallbackUI
labelFor
protected Component labelFor
JLabel
public JLabel(String text,
Icon icon,
int horizontalAlignment)
- Creates a
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.
- Parameters:
- 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
.
JLabel
public JLabel(String text,
int horizontalAlignment)
- Creates a
JLabel
instance with the specified
text and horizontal alignment.
The label is centered vertically in its display area.
- Parameters:
- text - The text to be displayed by the label.
- horizontalAlignment - One of the following constants
defined in
SwingConstants
:
LEFT
,
CENTER
, or
RIGHT
.
JLabel
public JLabel(String text)
- Creates a
JLabel
instance with the specified text.
The label is aligned against the left side of its display area,
and centered vertically.
- Parameters:
- text - The text to be displayed by the label.
JLabel
public JLabel(Icon image,
int horizontalAlignment)
- Creates a
JLabel
instance with the specified
image and horizontal alignment.
The label is centered vertically in its display area.
- Parameters:
- icon - The image to be displayed by the label.
- horizontalAlignment - One of the following constants
defined in
SwingConstants
:
LEFT
,
CENTER
, or
RIGHT
.
JLabel
public JLabel(Icon image)
- Creates a
JLabel
instance with the specified image.
The label is centered vertically and horizontally
in its display area.
- Parameters:
- icon - The image to be displayed by the label.
JLabel
public JLabel()
- Creates a
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.
getUI
public LabelUI getUI()
setUI
public void setUI(LabelUI ui)
updateUI
public void updateUI()
- Notification from the UIFactory that the L&F
has changed.
- Overrides:
- updateUI in class JComponent
getText
public String getText()
setText
public void setText(String text)
getIcon
public Icon getIcon()
setIcon
public void setIcon(Icon g)
setRepresentedKeyAccelerator
public void setRepresentedKeyAccelerator(char aKey)
getRepresentedKeyAccelerator
public char getRepresentedKeyAccelerator()
getDisabledIcon
public Icon getDisabledIcon()
setDisabledIcon
public void setDisabledIcon(Icon g)
checkHorizontalKey
protected int checkHorizontalKey(int x,
String s)
checkVerticalKey
protected int checkVerticalKey(int x,
String s)
setIconTextGap
public void setIconTextGap(int n)
getIconTextGap
public int getIconTextGap()
getVerticalAlignment
public int getVerticalAlignment()
- Returns the alignment of the label's contents along the Y axis.
- Returns:
- One of the following constants
defined in
SwingConstants
:
TOP
,
CENTER
, or
BOTTOM
.
- See Also:
- SwingConstants
setVerticalAlignment
public void setVerticalAlignment(int x)
- Sets the alignment of the label's contents along the Y axis.
- Parameters:
- x - One of the following constants
defined in
SwingConstants
:
TOP
,
CENTER
(the default), or
BOTTOM
.
- See Also:
- SwingConstants
getHorizontalAlignment
public int getHorizontalAlignment()
- Returns the alignment of the label's contents along the X axis.
- Returns:
- One of the following constants
defined in
SwingConstants
:
LEFT
,
CENTER
, or
RIGHT
.
- See Also:
- SwingConstants
setHorizontalAlignment
public void setHorizontalAlignment(int x)
- Sets the alignment of the label's contents along the X axis.
- Parameters:
- x - One of the following constants
defined in
SwingConstants
:
LEFT
(the default for text-only labels),
CENTER
(the default for image-only labels), or
RIGHT
.
- See Also:
- SwingConstants
getVerticalTextPosition
public int getVerticalTextPosition()
- Returns the vertical position of the label's text,
relative to its image.
- Returns:
- One of the following constants
defined in
SwingConstants
:
TOP
,
CENTER
, or
BOTTOM
.
- See Also:
- SwingConstants
setVerticalTextPosition
public void setVerticalTextPosition(int x)
- Sets the vertical position of the label's text,
relative to its image.
- Parameters:
- x - One of the following constants
defined in
SwingConstants
:
TOP
,
CENTER
(the default), or
BOTTOM
.
- See Also:
- SwingConstants
getHorizontalTextPosition
public int getHorizontalTextPosition()
- Returns the horizontal position of the label's text,
relative to its image.
- Returns:
- One of the following constants
defined in
SwingConstants
:
LEFT
,
CENTER
, or
RIGHT
.
- See Also:
- SwingConstants
setHorizontalTextPosition
public void setHorizontalTextPosition(int x)
- Sets the horizontal position of the label's text,
relative to its image.
- Parameters:
- x - One of the following constants
defined in
SwingConstants
:
LEFT
,
CENTER
, or
RIGHT
(the default).
- See Also:
- SwingConstants
setFont
public void setFont(Font x)
- Sets the font used to display the label's text.
- Parameters:
- x - The font to use.
- Overrides:
- setFont in class Component
getAccessibleName
public String getAccessibleName()
- Get the accessible name of this object.
- Returns:
- the localized name of the object -- can be null if this
object does not have a name
- Overrides:
- getAccessibleName in class JComponent
- See Also:
- setAccessibleName
getAccessibleRole
public AccessibleRole getAccessibleRole()
- Get the role of this object.
- Returns:
- an instance of AccessibleRole describing the role of the object
- Overrides:
- getAccessibleRole in class JComponent
- See Also:
- AccessibleRole
getLabelFor
public Component getLabelFor()
- Get the component this is labelling.
- Returns:
- the Component this is labelling. Can be null if this
does not label a Component.
setLabelFor
public void setLabelFor(Component c)
- Set the component this is labelling. Can be null if this does not
label a Component.
All Packages Class Hierarchy This Package Previous Next Index