|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JLabel
public class JLabel
A component that displays a static text message and/or an icon.
| Nested Class Summary | |
|---|---|
protected class |
JLabel.AccessibleJLabel
Provides the accessibility features for the JLabel
component. |
| 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, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
protected Component |
labelFor
The Component the label will give focus to when its mnemonic is activated. |
| Fields inherited from class javax.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 |
| Fields inherited from interface javax.swing.SwingConstants |
|---|
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
JLabel()
Creates a new vertically centered, horizontally on the leading edge JLabel object with text and no icon. |
|
JLabel(Icon image)
Creates a new vertically and horizontally centered JLabel object with no text and the given icon. |
|
JLabel(Icon image,
int horizontalAlignment)
Creates a new vertically centered JLabel object with no text and the given icon and horizontal alignment. |
|
JLabel(String text)
Creates a new horizontally leading and vertically centered JLabel object with no icon and the given text. |
|
JLabel(String text,
Icon icon,
int horizontalAlignment)
Creates a new vertically centered JLabel object with the given text, icon, and horizontal alignment. |
|
JLabel(String text,
int horizontalAlignment)
Creates a new vertically centered JLabel object with no icon and the given text and horizontal alignment. |
|
| Method Summary | |
|---|---|
protected int |
checkHorizontalKey(int key,
String message)
Checks the specified key to ensure that it is valid as a horizontal alignment, throwing an IllegalArgumentException if the key is
invalid. |
protected int |
checkVerticalKey(int key,
String message)
Checks the specified key to ensure that it is valid as a vertical alignment, throwing an IllegalArgumentException if the key is
invalid. |
AccessibleContext |
getAccessibleContext()
Returns the object that provides accessibility features for this JLabel component. |
Icon |
getDisabledIcon()
Returns the disabled icon. |
int |
getDisplayedMnemonic()
Returns the keycode that is used for the label's mnemonic. |
int |
getDisplayedMnemonicIndex()
Returns the index of the character in the label's text that will be underlined (to indicate that it is the mnemonic character), or -1 if no character is to be underlined. |
int |
getHorizontalAlignment()
Returns the horizontal alignment of the label (one of SwingConstants.LEFT,
SwingConstants.CENTER, SwingConstants.RIGHT, SwingConstants.LEADING and SwingConstants.TRAILING). |
int |
getHorizontalTextPosition()
Returns the horizontal position of the label's text relative to the icon. |
Icon |
getIcon()
Returns the active icon. |
int |
getIconTextGap()
Returns the gap between the icon and the text. |
Component |
getLabelFor()
Returns the component that this JLabel is providing the label
for. |
String |
getText()
Returns the text displayed by the label. |
LabelUI |
getUI()
Returns the label's UI delegate. |
String |
getUIClassID()
Returns a name to identify which look and feel class will be the UI delegate for this label. |
int |
getVerticalAlignment()
Returns the vertical alignment of the label (one of SwingConstants.TOP, SwingConstants.CENTER and SwingConstants.BOTTOM). |
int |
getVerticalTextPosition()
Returns the vertical position of the label's text relative to the icon. |
boolean |
imageUpdate(Image img,
int infoflags,
int x,
int y,
int w,
int h)
Returns false if the current icon image (current icon will depend on whether the label is enabled) is not equal to the passed in image. |
protected String |
paramString()
Returns a string describing the attributes for the JLabel
component, for use in debugging. |
void |
setDisabledIcon(Icon newIcon)
Sets the icon displayed when the label is disabled (this is a bound property with the name 'disabledIcon'). |
void |
setDisplayedMnemonic(char mnemonic)
Sets the character that will be the label's mnemonic. |
void |
setDisplayedMnemonic(int mnemonic)
Sets the keycode that will be the label's mnemonic (this is a bound property with the name 'displayedMnemonic'). |
void |
setDisplayedMnemonicIndex(int newIndex)
Sets the index of the character in the text that will be underlined to indicate that it is the mnemonic character for the label. |
void |
setFont(Font f)
Sets the font for the label (this a bound property with the name 'font'). |
void |
setHorizontalAlignment(int alignment)
Sets the horizontal alignment for the label (this is a bound property with the name 'horizontalAlignment'). |
void |
setHorizontalTextPosition(int textPosition)
Sets the horizontal position of the label's text relative to the icon (this is a bound property with the name 'horizontalTextPosition'). |
void |
setIcon(Icon newIcon)
Sets the icon for the label (this is a bound property with the name 'icon'). |
void |
setIconTextGap(int newGap)
Sets the gap between the icon and the text, in the case that both are visible (this is a bound property with the name 'iconTextGap'). |
void |
setLabelFor(Component c)
Sets the component that this JLabel is providing the label
for (this is a bound property with the name 'labelFor'). |
void |
setText(String newText)
Sets the text for the label and sends a PropertyChangeEvent (with
the name 'text') to all registered listeners. |
void |
setUI(LabelUI ui)
Sets the label's UI delegate. |
void |
setVerticalAlignment(int alignment)
Sets the vertical alignment for the label (this is a bound property with the name 'verticalAlignment'). |
void |
setVerticalTextPosition(int textPosition)
Sets the vertical position of the label's text relative to the icon (this is a bound property with the name 'verticalTextPosition'). |
void |
updateUI()
Resets the label's UI delegate to the default UI for the current look and feel. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected Component labelFor
| Constructor Detail |
|---|
public JLabel()
public JLabel(Icon image)
image - The icon to use with the label, null permitted.
public JLabel(Icon image,
int horizontalAlignment)
image - The icon to use with the label, null premitted.horizontalAlignment - The horizontal alignment of the label, must be
either CENTER, LEFT, RIGHT,
LEADING or TRAILING.public JLabel(String text)
text - The text to use with the label, null permitted.
public JLabel(String text,
int horizontalAlignment)
text - The text to use with the label, null permitted.horizontalAlignment - The horizontal alignment of the label, must be
either CENTER, LEFT, RIGHT,
LEADING or TRAILING.
public JLabel(String text,
Icon icon,
int horizontalAlignment)
text - The text to use with the label, null permitted.icon - The icon to use with the label, null premitted.horizontalAlignment - The horizontal alignment of the label, must be
either CENTER, LEFT, RIGHT,
LEADING or TRAILING.| Method Detail |
|---|
public LabelUI getUI()
public void setUI(LabelUI ui)
ui - The label's UI delegate (null not permitted).public void updateUI()
updateUI in class JComponentpublic String getUIClassID()
getUIClassID in class JComponent"LabelUI"JComponent.setUI(javax.swing.plaf.ComponentUI),
JComponent.updateUI()protected String paramString()
JLabel
component, for use in debugging. The return value is guaranteed to be
non-null, but the format of the string may vary between
implementations.
paramString in class JComponentJLabel.public String getText()
null).setText(String)public void setText(String newText)
PropertyChangeEvent (with
the name 'text') to all registered listeners. This method will also
update the displayedMnemonicIndex, if necessary.
newText - The text (null permitted).getText(),
getDisplayedMnemonicIndex()public Icon getIcon()
setIcon(Icon),
getDisabledIcon()public void setIcon(Icon newIcon)
newIcon - The icon (null permitted).getIcon(),
setDisabledIcon(Icon)public Icon getDisabledIcon()
null and the active icon
is an ImageIcon, this method returns a grayed version of the icon.
The grayed version of the icon becomes the disabledIcon.
setDisabledIcon(Icon)public void setDisabledIcon(Icon newIcon)
newIcon - The disabled icon (null permitted).getDisabledIcon()public void setDisplayedMnemonic(int mnemonic)
mnemonic - The keycode to use for the mnemonic.getDisplayedMnemonic()public void setDisplayedMnemonic(char mnemonic)
mnemonic - The character to use for the mnemonic (this will be
converted to the equivalent upper case character).getDisplayedMnemonic()public int getDisplayedMnemonic()
setDisplayedMnemonic(int)
public void setDisplayedMnemonicIndex(int newIndex)
throws IllegalArgumentException
getDisplayedMnemonic().
newIndex - The index of the character to underline.
IllegalArgumentException - If index less than -1 or index is greater
than or equal to the label length.getDisplayedMnemonicIndex()public int getDisplayedMnemonicIndex()
setDisplayedMnemonicIndex(int)
protected int checkHorizontalKey(int key,
String message)
IllegalArgumentException if the key is
invalid. Valid keys are SwingConstants.LEFT, SwingConstants.CENTER, SwingConstants.RIGHT,
SwingConstants.LEADING and SwingConstants.TRAILING.
key - The key to check.message - The message of the exception to be thrown if the key is
invalid.
IllegalArgumentException - If the key is invalid.
protected int checkVerticalKey(int key,
String message)
IllegalArgumentException if the key is
invalid. Valid keys are SwingConstants.TOP, SwingConstants.CENTER and SwingConstants.BOTTOM.
key - The key to check.message - The message of the exception to be thrown if the key is
invalid.
IllegalArgumentException - If the key is invalid.public int getIconTextGap()
setIconTextGap(int)public void setIconTextGap(int newGap)
newGap - The gap (in pixels).getIconTextGap()public int getVerticalAlignment()
SwingConstants.TOP, SwingConstants.CENTER and SwingConstants.BOTTOM). The default value
depends on the installed look and feel, but is usually SwingConstants.CENTER.
setVerticalAlignment(int)public void setVerticalAlignment(int alignment)
SwingConstants.TOP, SwingConstants.CENTER and
SwingConstants.BOTTOM.
alignment - The vertical alignment of the label.
IllegalArgumentException - if alignment is not one of
the specified values.getVerticalAlignment()public int getHorizontalAlignment()
SwingConstants.LEFT,
SwingConstants.CENTER, SwingConstants.RIGHT, SwingConstants.LEADING and SwingConstants.TRAILING).
The default value depends on the installed look and feel, but is usually
SwingConstants.LEFT.
setHorizontalAlignment(int)public void setHorizontalAlignment(int alignment)
SwingConstants.LEFT,
SwingConstants.CENTER, SwingConstants.RIGHT, SwingConstants.LEADING and SwingConstants.TRAILING.
alignment - The horizontal alignment of the label.
IllegalArgumentException - if alignment is not one of
the specified values.getHorizontalAlignment()public int getVerticalTextPosition()
SwingConstants.TOP, SwingConstants.CENTER and SwingConstants.BOTTOM.
setVerticalTextPosition(int)public void setVerticalTextPosition(int textPosition)
SwingConstants.TOP, SwingConstants.CENTER and SwingConstants.BOTTOM.
textPosition - The vertical text position.
IllegalArgumentException - if textPosition is not one
of the specified values.public int getHorizontalTextPosition()
SwingConstants.LEFT, SwingConstants.CENTER, SwingConstants.RIGHT,
SwingConstants.LEADING and SwingConstants.TRAILING.
setHorizontalTextPosition(int)public void setHorizontalTextPosition(int textPosition)
SwingConstants.LEFT, SwingConstants.CENTER, SwingConstants.RIGHT,
SwingConstants.LEADING and SwingConstants.TRAILING.
textPosition - The horizontal text position.
IllegalArgumentException - if textPosition is not one
of the specified values.
public boolean imageUpdate(Image img,
int infoflags,
int x,
int y,
int w,
int h)
imageUpdate in interface ImageObserverimageUpdate in class Componentimg - The image to check.infoflags - The bitwise inclusive OR of ABORT, ALLBITS, ERROR,
FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, and WIDTHx - The x positiony - The y positionw - The widthh - The height
ImageObserver,
Graphics.drawImage(Image, int, int, Color, ImageObserver),
Graphics.drawImage(Image, int, int, ImageObserver),
Graphics.drawImage(Image, int, int, int, int, Color, ImageObserver),
Graphics.drawImage(Image, int, int, int, int, ImageObserver),
ImageObserver.imageUpdate(Image, int, int, int, int, int)public Component getLabelFor()
JLabel is providing the label
for. This component will typically receive the focus when the label's
mnemonic key is activated via the keyboard.
null).public void setLabelFor(Component c)
JLabel is providing the label
for (this is a bound property with the name 'labelFor'). This component
will typically receive the focus when the label's mnemonic key is
activated via the keyboard.
c - the component (null permitted).getLabelFor()public void setFont(Font f)
setFont in class JComponentf - The font (null permitted).Component.getFont()public AccessibleContext getAccessibleContext()
JLabel component.
getAccessibleContext in interface AccessiblegetAccessibleContext in class JComponentJLabel.AccessibleJLabel).
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||