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
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?]


Variable Index

 o fallbackUI

Constructor Index

 o JLabel()
Creates a JLabel instance with no image and with an empty string for the title.
 o JLabel(Icon)
Creates a JLabel instance with the specified image.
 o JLabel(Icon, int)
Creates a JLabel instance with the specified image and horizontal alignment.
 o JLabel(String)
Creates a JLabel instance with the specified text.
 o JLabel(String, Icon, int)
Creates a JLabel instance with the specified text, image, and horizontal alignment.
 o JLabel(String, int)
Creates a JLabel instance with the specified text and horizontal alignment.

Method Index

 o checkHorizontalKey(int, String)
 o checkVerticalKey(int, String)
 o getDisabledIcon()
 o getHorizontalAlignment()
Returns the alignment of the label's contents along the X axis.
 o getHorizontalTextPosition()
Returns the horizontal position of the label's text, relative to its image.
 o getIcon()
 o getIconTextGap()
 o getRepresentedKeyAccelerator()
 o getText()
 o getUI()
 o getVerticalAlignment()
Returns the alignment of the label's contents along the Y axis.
 o getVerticalTextPosition()
Returns the vertical position of the label's text, relative to its image.
 o setDisabledIcon(Icon)
 o setFont(Font)
Sets the font used to display the label's text.
 o setHorizontalAlignment(int)
Sets the alignment of the label's contents along the X axis.
 o setHorizontalTextPosition(int)
Sets the horizontal position of the label's text, relative to its image.
 o setIcon(Icon)
 o setIconTextGap(int)
 o setRepresentedKeyAccelerator(char)
 o setText(String)
 o setUI(LabelUI)
 o setVerticalAlignment(int)
Sets the alignment of the label's contents along the Y axis.
 o setVerticalTextPosition(int)
Sets the vertical position of the label's text, relative to its image.
 o updateUI()
Notification from the UIFactory that the L&F has changed.

Variables

 o fallbackUI
 protected static String fallbackUI

Constructors

 o 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 GraphicsUtilsConstants: LEFT, CENTER, or RIGHT.
 o 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 GraphicsUtilsConstants: LEFT, CENTER, or RIGHT.
 o 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.
 o 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 GraphicsUtilsConstants: LEFT, CENTER, or RIGHT.
 o 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.
 o 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.

Methods

 o getUI
 public LabelUI getUI()
 o setUI
 public void setUI(LabelUI ui)
 o updateUI
 public void updateUI()
Notification from the UIFactory that the L&F has changed.

Overrides:
updateUI in class JComponent
 o getText
 public String getText()
 o setText
 public void setText(String text)
 o getIcon
 public Icon getIcon()
 o setIcon
 public void setIcon(Icon g)
 o setRepresentedKeyAccelerator
 public void setRepresentedKeyAccelerator(char aKey)
 o getRepresentedKeyAccelerator
 public char getRepresentedKeyAccelerator()
 o getDisabledIcon
 public Icon getDisabledIcon()
 o setDisabledIcon
 public void setDisabledIcon(Icon g)
 o checkHorizontalKey
 protected int checkHorizontalKey(int x,
                                  String s)
 o checkVerticalKey
 protected int checkVerticalKey(int x,
                                String s)
 o setIconTextGap
 public void setIconTextGap(int n)
 o getIconTextGap
 public int getIconTextGap()
 o getVerticalAlignment
 public int getVerticalAlignment()
Returns the alignment of the label's contents along the Y axis.

Returns:
One of the following constants defined in GraphicsUtilsConstants: TOP, CENTER, or BOTTOM.
See Also:
GraphicsUtilsConstants
 o 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 GraphicsUtilsConstants: TOP, CENTER (the default), or BOTTOM.
See Also:
GraphicsUtilsConstants
 o getHorizontalAlignment
 public int getHorizontalAlignment()
Returns the alignment of the label's contents along the X axis.

Returns:
One of the following constants defined in GraphicsUtilsConstants: LEFT, CENTER, or RIGHT.
See Also:
GraphicsUtilsConstants
 o 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 GraphicsUtilsConstants: LEFT (the default for text-only labels), CENTER (the default for image-only labels), or RIGHT.
See Also:
GraphicsUtilsConstants
 o 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 GraphicsUtilsConstants: TOP, CENTER, or BOTTOM.
See Also:
GraphicsUtilsConstants
 o 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 GraphicsUtilsConstants: TOP, CENTER (the default), or BOTTOM.
See Also:
GraphicsUtilsConstants
 o 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 GraphicsUtilsConstants: LEFT, CENTER, or RIGHT.
See Also:
GraphicsUtilsConstants
 o 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 GraphicsUtilsConstants: LEFT, CENTER, or RIGHT (the default).
See Also:
GraphicsUtilsConstants
 o 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

All Packages  Class Hierarchy  This Package  Previous  Next  Index