Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
Nested Class Summary | |
protected class |
|
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 |
|
Fields inherited from class javax.swing.JComponent | |
TOOL_TIP_TEXT_KEY , UNDEFINED_CONDITION , WHEN_ANCESTOR_OF_FOCUSED_COMPONENT , WHEN_FOCUSED , WHEN_IN_FOCUSED_WINDOW , accessibleContext , listenerList , ui |
Fields inherited from class java.awt.Component | |
BOTTOM_ALIGNMENT , CENTER_ALIGNMENT , LEFT_ALIGNMENT , RIGHT_ALIGNMENT , TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver | |
ABORT , ALLBITS , ERROR , FRAMEBITS , HEIGHT , PROPERTIES , SOMEBITS , WIDTH |
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 |
Constructor Summary | |
| |
Method Summary | |
protected int |
|
protected int |
|
AccessibleContext |
|
Icon |
|
int |
|
int |
|
int |
|
int |
|
Icon |
|
int |
|
Component |
|
String |
|
LabelUI |
|
String |
|
int |
|
int |
|
boolean |
|
protected String |
|
void |
|
void |
|
void |
|
void |
|
void | |
void |
|
void |
|
void | |
void |
|
void |
|
void |
|
void | |
void |
|
void |
|
void |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public JLabel()
Creates a new vertically centered, horizontally on the leading edge JLabel object with text and no icon.
public JLabel(String text)
Creates a new horizontally leading and vertically centered JLabel object with no icon and the given text.
- Parameters:
text
- The text to use with the label,null
permitted.
public JLabel(String text, int horizontalAlignment)
Creates a new vertically centered JLabel object with no icon and the given text and horizontal alignment.
- Parameters:
text
- The text to use with the label,null
permitted.horizontalAlignment
- The horizontal alignment of the label, must be eitherCENTER
,LEFT
,RIGHT
,LEADING
orTRAILING
.
public JLabel(String text, Icon icon, int horizontalAlignment)
Creates a new vertically centered JLabel object with the given text, icon, and horizontal alignment.
- Parameters:
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 eitherCENTER
,LEFT
,RIGHT
,LEADING
orTRAILING
.
public JLabel(Icon image)
Creates a new vertically and horizontally centered JLabel object with no text and the given icon.
- Parameters:
image
- The icon to use with the label,null
permitted.
public JLabel(Icon image, int horizontalAlignment)
Creates a new vertically centered JLabel object with no text and the given icon and horizontal alignment. By default, the text is TRAILING the image.
- Parameters:
image
- The icon to use with the label,null
premitted.horizontalAlignment
- The horizontal alignment of the label, must be eitherCENTER
,LEFT
,RIGHT
,LEADING
orTRAILING
.
protected int checkHorizontalKey(int key, String message)
Checks the specified key to ensure that it is valid as a horizontal alignment, throwing anIllegalArgumentException
if the key is invalid. Valid keys areSwingConstants.LEFT
,SwingConstants.CENTER
,SwingConstants.RIGHT
,SwingConstants.LEADING
andSwingConstants.TRAILING
.
- Parameters:
key
- The key to check.message
- The message of the exception to be thrown if the key is invalid.
- Returns:
- The key if it is valid.
- Throws:
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 anIllegalArgumentException
if the key is invalid. Valid keys areSwingConstants.TOP
,SwingConstants.CENTER
andSwingConstants.BOTTOM
.
- Parameters:
key
- The key to check.message
- The message of the exception to be thrown if the key is invalid.
- Returns:
- The key if it is valid.
- Throws:
IllegalArgumentException
- If the key is invalid.
public AccessibleContext getAccessibleContext()
Returns the object that provides accessibility features for thisJLabel
component.
- Specified by:
- getAccessibleContext in interface Accessible
- Overrides:
- getAccessibleContext in interface JComponent
- Returns:
- The accessible context (an instance of
JLabel.AccessibleJLabel
).
public Icon getDisabledIcon()
Returns the disabled icon. The disabled icon is painted when the label is disabled. If the disabled icon isnull
and the active icon is anImageIcon
, this method returns a grayed version of the icon. The grayed version of the icon becomes thedisabledIcon
.
- Returns:
- The disabled icon.
- See Also:
setDisabledIcon(Icon)
public int getDisplayedMnemonic()
Returns the keycode that is used for the label's mnemonic.
- Returns:
- The keycode that is used for the label's mnemonic.
- See Also:
setDisplayedMnemonic(int)
public 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.
- Returns:
- The index of the character that will be underlined.
- Since:
- 1.4
- See Also:
setDisplayedMnemonicIndex(int)
public int getHorizontalAlignment()
Returns the horizontal alignment of the label (one ofSwingConstants.LEFT
,SwingConstants.CENTER
,SwingConstants.RIGHT
,SwingConstants.LEADING
andSwingConstants.TRAILING
). The default value depends on the installed look and feel, but is usuallySwingConstants.LEFT
.
- Returns:
- The horizontal alignment.
- See Also:
setHorizontalAlignment(int)
public int getHorizontalTextPosition()
Returns the horizontal position of the label's text relative to the icon. This will be one ofSwingConstants.LEFT
,SwingConstants.CENTER
,SwingConstants.RIGHT
,SwingConstants.LEADING
andSwingConstants.TRAILING
.
- Returns:
- The horizontal position of the label's text relative to the icon.
- See Also:
setHorizontalTextPosition(int)
public Icon getIcon()
Returns the active icon. The active icon is painted when the label is enabled.
- Returns:
- The active icon.
- See Also:
setIcon(Icon)
,getDisabledIcon()
public int getIconTextGap()
Returns the gap between the icon and the text.
- Returns:
- The gap between the icon and the text.
- See Also:
setIconTextGap(int)
public Component getLabelFor()
Returns the component that thisJLabel
is providing the label for. This component will typically receive the focus when the label's mnemonic key is activated via the keyboard.
- Returns:
- The component (possibly
null
).
public String getText()
Returns the text displayed by the label.
- Returns:
- The label text (possibly
null
).
- See Also:
setText(String)
public String getUIClassID()
Returns a name to identify which look and feel class will be the UI delegate for this label.
- Overrides:
- getUIClassID in interface JComponent
- Returns:
"LabelUI"
public int getVerticalAlignment()
Returns the vertical alignment of the label (one ofSwingConstants.TOP
,SwingConstants.CENTER
andSwingConstants.BOTTOM
). The default value depends on the installed look and feel, but is usuallySwingConstants.CENTER
.
- Returns:
- The vertical alignment.
- See Also:
setVerticalAlignment(int)
public int getVerticalTextPosition()
Returns the vertical position of the label's text relative to the icon. This will be one ofSwingConstants.TOP
,SwingConstants.CENTER
andSwingConstants.BOTTOM
.
- Returns:
- The vertical position of the label's text relative to the icon.
- See Also:
setVerticalTextPosition(int)
public 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.
- Specified by:
- imageUpdate in interface ImageObserver
- Overrides:
- imageUpdate in interface Component
- Parameters:
img
- 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
- Returns:
- Whether the current icon image is equal to the image given.
protected String paramString()
Returns a string describing the attributes for theJLabel
component, for use in debugging. The return value is guaranteed to be non-null
, but the format of the string may vary between implementations.
- Overrides:
- paramString in interface JComponent
- Returns:
- A string describing the attributes of the
JLabel
.
public void setDisabledIcon(Icon newIcon)
Sets the icon displayed when the label is disabled (this is a bound property with the name 'disabledIcon').
- Parameters:
newIcon
- The disabled icon (null
permitted).
- See Also:
getDisabledIcon()
public void setDisplayedMnemonic(char mnemonic)
Sets the character that will be the label's mnemonic. If the label is used as a label for another component, the label will give focus to that component when the mnemonic is activated via the keyboard.
- Parameters:
mnemonic
- The character to use for the mnemonic (this will be converted to the equivalent upper case character).
- See Also:
getDisplayedMnemonic()
public void setDisplayedMnemonic(int mnemonic)
Sets the keycode that will be the label's mnemonic (this is a bound property with the name 'displayedMnemonic'). If the label is used as a label for another component, the label will give focus to that component when the mnemonic is activated.
- Parameters:
mnemonic
- The keycode to use for the mnemonic.
- See Also:
getDisplayedMnemonic()
public void setDisplayedMnemonicIndex(int newIndex) throws IllegalArgumentException
Sets the index of the character in the text that will be underlined to indicate that it is the mnemonic character for the label. You only need to call this method if you wish to override the automatically calculated character index. For instance, for a label "Find Next" with the mnemonic character 'n', you might wish to underline the second occurrence of 'n' rather than the first (which is the default).
Note that this method does not validate the character at the specified index to ensure that it matches the key code returned bygetDisplayedMnemonic()
.
- Parameters:
newIndex
- The index of the character to underline.
- Throws:
IllegalArgumentException
- If index less than -1 or index is greater than or equal to the label length.
- Since:
- 1.4
- See Also:
getDisplayedMnemonicIndex()
public void setFont(Font f)
Sets the font for the label (this a bound property with the name 'font').
- Overrides:
- setFont in interface JComponent
- Parameters:
f
- The font (null
permitted).
public void setHorizontalAlignment(int alignment)
Sets the horizontal alignment for the label (this is a bound property with the name 'horizontalAlignment'). The horizontal alignment determines where the label (icon and text) will be placed horizontally within the component bounds. Valid alignment codes areSwingConstants.LEFT
,SwingConstants.CENTER
,SwingConstants.RIGHT
,SwingConstants.LEADING
andSwingConstants.TRAILING
.
- Parameters:
alignment
- The horizontal alignment of the label.
- Throws:
IllegalArgumentException
- ifalignment
is not one of the specified values.
- See Also:
getHorizontalAlignment()
public 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'). Valid positions areSwingConstants.LEFT
,SwingConstants.CENTER
,SwingConstants.RIGHT
,SwingConstants.LEADING
andSwingConstants.TRAILING
.
- Parameters:
textPosition
- The horizontal text position.
- Throws:
IllegalArgumentException
- iftextPosition
is not one of the specified values.
public void setIcon(Icon newIcon)
Sets the icon for the label (this is a bound property with the name 'icon'). This icon will be displayed when the label is enabled.
- Parameters:
newIcon
- The icon (null
permitted).
- See Also:
getIcon()
,setDisabledIcon(Icon)
public 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').
- Parameters:
newGap
- The gap (in pixels).
- See Also:
getIconTextGap()
public void setLabelFor(Component c)
Sets the component that thisJLabel
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.
- Parameters:
c
- the component (null
permitted).
- See Also:
getLabelFor()
public void setText(String newText)
Sets the text for the label and sends aPropertyChangeEvent
(with the name 'text') to all registered listeners. This method will also update thedisplayedMnemonicIndex
, if necessary.
- Parameters:
newText
- The text (null
permitted).
- See Also:
getText()
,getDisplayedMnemonicIndex()
public void setUI(LabelUI ui)
Sets the label's UI delegate.
- Parameters:
ui
- The label's UI delegate (null
not permitted).
public void setVerticalAlignment(int alignment)
Sets the vertical alignment for the label (this is a bound property with the name 'verticalAlignment'). The vertical alignment determines where the label (icon and text) will be placed vertically within the component bounds. Valid alignment codes areSwingConstants.TOP
,SwingConstants.CENTER
andSwingConstants.BOTTOM
.
- Parameters:
alignment
- The vertical alignment of the label.
- Throws:
IllegalArgumentException
- ifalignment
is not one of the specified values.
- See Also:
getVerticalAlignment()
public 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'). Valid positions areSwingConstants.TOP
,SwingConstants.CENTER
andSwingConstants.BOTTOM
.
- Parameters:
textPosition
- The vertical text position.
- Throws:
IllegalArgumentException
- iftextPosition
is not one of the specified values.
public void updateUI()
Resets the label's UI delegate to the default UI for the current look and feel.
- Overrides:
- updateUI in interface JComponent