JLabel (Java 2 Platform SE 5.0) (original) (raw)
javax.swing
Class JLabel
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JLabel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants
Direct Known Subclasses:
BasicComboBoxRenderer, DefaultListCellRenderer, DefaultTableCellRenderer, DefaultTreeCellRenderer
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 leading edge 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 on the trailing edge of the image, with the text and image vertically aligned.
A label's leading and trailing edge are determined from the value of itsComponentOrientation property. At present, the default ComponentOrientation setting maps the leading edge to left and the trailing edge to right.
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.
See How to Use Labels in The Java Tutorial for further documentation.
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans
package. Please see XMLEncoder.
Nested Class Summary | |
---|---|
protected class | JLabel.AccessibleJLabel The class used to obtain the accessible role for this object. |
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 |
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 JLabel instance with no image and with an empty string for the title. |
JLabel(Icon image) Creates a JLabel instance with the specified image. |
[JLabel](../../javax/swing/JLabel.html#JLabel%28javax.swing.Icon, int%29)(Icon image, int horizontalAlignment) Creates a JLabel instance with the specified image and horizontal alignment. |
JLabel(String text) Creates a JLabel instance with the specified text. |
[JLabel](../../javax/swing/JLabel.html#JLabel%28java.lang.String, javax.swing.Icon, int%29)(String text,Icon icon, int horizontalAlignment) Creates a JLabel instance with the specified text, image, and horizontal alignment. |
[JLabel](../../javax/swing/JLabel.html#JLabel%28java.lang.String, int%29)(String text, int horizontalAlignment) Creates a JLabel instance with the specified text and horizontal alignment. |
Method Summary | |
---|---|
protected int | [checkHorizontalKey](../../javax/swing/JLabel.html#checkHorizontalKey%28int, java.lang.String%29)(int key,String message) Verify that key is a legal value for the horizontalAlignment properties. |
protected int | [checkVerticalKey](../../javax/swing/JLabel.html#checkVerticalKey%28int, java.lang.String%29)(int key,String message) Verify that key is a legal value for the verticalAlignment or verticalTextPosition properties. |
AccessibleContext | getAccessibleContext() Get the AccessibleContext of this object |
Icon | getDisabledIcon() Returns the icon used by the label when it's disabled. |
int | getDisplayedMnemonic() Return the keycode that indicates a mnemonic key. |
int | getDisplayedMnemonicIndex() Returns the character, as an index, that the look and feel should provide decoration for as representing the mnemonic character. |
int | getHorizontalAlignment() Returns the alignment of the label's contents along the X axis. |
int | getHorizontalTextPosition() Returns the horizontal position of the label's text, relative to its image. |
Icon | getIcon() Returns the graphic image (glyph, icon) that the label displays. |
int | getIconTextGap() Returns the amount of space between the text and the icon displayed in this label. |
Component | getLabelFor() Get the component this is labelling. |
String | getText() Returns the text string that the label displays. |
LabelUI | getUI() Returns the L&F object that renders this component. |
String | getUIClassID() Returns a string that specifies the name of the l&f class that renders this component. |
int | getVerticalAlignment() Returns the alignment of the label's contents along the Y axis. |
int | getVerticalTextPosition() Returns the vertical position of the label's text, relative to its image. |
boolean | [imageUpdate](../../javax/swing/JLabel.html#imageUpdate%28java.awt.Image, int, int, int, int, int%29)(Image img, int infoflags, int x, int y, int w, int h) This is overridden to return false if the current Icon's Image is not equal to the passed in Image img. |
protected String | paramString() Returns a string representation of this JLabel. |
void | setDisabledIcon(Icon disabledIcon) Set the icon to be displayed if this JLabel is "disabled" (JLabel.setEnabled(false)). |
void | setDisplayedMnemonic(char aChar) Specifies the displayedMnemonic as a char value. |
void | setDisplayedMnemonic(int key) Specify a keycode that indicates a mnemonic key. |
void | setDisplayedMnemonicIndex(int index) Provides a hint to the look and feel as to which character in the text should be decorated to represent the mnemonic. |
void | setHorizontalAlignment(int alignment) Sets the alignment of the label's contents along the X axis. |
void | setHorizontalTextPosition(int textPosition) Sets the horizontal position of the label's text, relative to its image. |
void | setIcon(Icon icon) Defines the icon this component will display. |
void | setIconTextGap(int iconTextGap) If both the icon and text properties are set, this property defines the space between them. |
void | setLabelFor(Component c) Set the component this is labelling. |
void | setText(String text) Defines the single line of text this component will display. |
void | setUI(LabelUI ui) Sets the L&F object that renders this component. |
void | setVerticalAlignment(int alignment) Sets the alignment of the label's contents along the Y axis. |
void | setVerticalTextPosition(int textPosition) Sets the vertical position of the label's text, relative to its image. |
void | updateUI() Resets the UI property to a value from the current look and feel. |
Methods inherited from class javax.swing.JComponent |
---|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, [contains](../../javax/swing/JComponent.html#contains%28int, int%29), createToolTip, disable, enable, [firePropertyChange](../../javax/swing/JComponent.html#firePropertyChange%28java.lang.String, boolean, boolean%29), [firePropertyChange](../../javax/swing/JComponent.html#firePropertyChange%28java.lang.String, char, char%29), [firePropertyChange](../../javax/swing/JComponent.html#firePropertyChange%28java.lang.String, int, int%29), [fireVetoableChange](../../javax/swing/JComponent.html#fireVetoableChange%28java.lang.String, java.lang.Object, java.lang.Object%29), getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, [paintImmediately](../../javax/swing/JComponent.html#paintImmediately%28int, int, int, int%29), paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, [processKeyBinding](../../javax/swing/JComponent.html#processKeyBinding%28javax.swing.KeyStroke, java.awt.event.KeyEvent, int, boolean%29), processKeyEvent, processMouseEvent, processMouseMotionEvent, [putClientProperty](../../javax/swing/JComponent.html#putClientProperty%28java.lang.Object, java.lang.Object%29), [registerKeyboardAction](../../javax/swing/JComponent.html#registerKeyboardAction%28java.awt.event.ActionListener, javax.swing.KeyStroke, int%29), [registerKeyboardAction](../../javax/swing/JComponent.html#registerKeyboardAction%28java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int%29), removeAncestorListener, removeNotify, removeVetoableChangeListener, [repaint](../../javax/swing/JComponent.html#repaint%28long, int, int, int, int%29), repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, [reshape](../../javax/swing/JComponent.html#reshape%28int, int, int, int%29), revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, [setFocusTraversalKeys](../../javax/swing/JComponent.html#setFocusTraversalKeys%28int, java.util.Set%29), setFont, setForeground, setInheritsPopupMenu, [setInputMap](../../javax/swing/JComponent.html#setInputMap%28int, javax.swing.InputMap%29), setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
Methods inherited from class java.awt.Container |
---|
add, [add](../../java/awt/Container.html#add%28java.awt.Component, int%29), [add](../../java/awt/Container.html#add%28java.awt.Component, java.lang.Object%29), [add](../../java/awt/Container.html#add%28java.awt.Component, java.lang.Object, int%29), [add](../../java/awt/Container.html#add%28java.lang.String, java.awt.Component%29), addContainerListener, [addImpl](../../java/awt/Container.html#addImpl%28java.awt.Component, java.lang.Object, int%29), addPropertyChangeListener, [addPropertyChangeListener](../../java/awt/Container.html#addPropertyChangeListener%28java.lang.String, java.beans.PropertyChangeListener%29), applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, [findComponentAt](../../java/awt/Container.html#findComponentAt%28int, int%29), findComponentAt, getComponent, [getComponentAt](../../java/awt/Container.html#getComponentAt%28int, int%29), getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, [list](../../java/awt/Container.html#list%28java.io.PrintStream, int%29), [list](../../java/awt/Container.html#list%28java.io.PrintWriter, int%29), [locate](../../java/awt/Container.html#locate%28int, int%29), minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, [setComponentZOrder](../../java/awt/Container.html#setComponentZOrder%28java.awt.Component, int%29), setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
Methods inherited from class java.awt.Component |
---|
[action](../../java/awt/Component.html#action%28java.awt.Event, java.lang.Object%29), add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, [checkImage](../../java/awt/Component.html#checkImage%28java.awt.Image, java.awt.image.ImageObserver%29), [checkImage](../../java/awt/Component.html#checkImage%28java.awt.Image, int, int, java.awt.image.ImageObserver%29), [coalesceEvents](../../java/awt/Component.html#coalesceEvents%28java.awt.AWTEvent, java.awt.AWTEvent%29), contains, createImage, [createImage](../../java/awt/Component.html#createImage%28int, int%29), [createVolatileImage](../../java/awt/Component.html#createVolatileImage%28int, int%29), [createVolatileImage](../../java/awt/Component.html#createVolatileImage%28int, int, java.awt.ImageCapabilities%29), disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, byte, byte%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, double, double%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, float, float%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, long, long%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, java.lang.Object, java.lang.Object%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, short, short%29), getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, [gotFocus](../../java/awt/Component.html#gotFocus%28java.awt.Event, java.lang.Object%29), handleEvent, hasFocus, hide, [inside](../../java/awt/Component.html#inside%28int, int%29), isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, [keyDown](../../java/awt/Component.html#keyDown%28java.awt.Event, int%29), [keyUp](../../java/awt/Component.html#keyUp%28java.awt.Event, int%29), list, list, list, location, [lostFocus](../../java/awt/Component.html#lostFocus%28java.awt.Event, java.lang.Object%29), [mouseDown](../../java/awt/Component.html#mouseDown%28java.awt.Event, int, int%29), [mouseDrag](../../java/awt/Component.html#mouseDrag%28java.awt.Event, int, int%29), [mouseEnter](../../java/awt/Component.html#mouseEnter%28java.awt.Event, int, int%29), [mouseExit](../../java/awt/Component.html#mouseExit%28java.awt.Event, int, int%29), [mouseMove](../../java/awt/Component.html#mouseMove%28java.awt.Event, int, int%29), [mouseUp](../../java/awt/Component.html#mouseUp%28java.awt.Event, int, int%29), [move](../../java/awt/Component.html#move%28int, int%29), nextFocus, paintAll, postEvent, [prepareImage](../../java/awt/Component.html#prepareImage%28java.awt.Image, java.awt.image.ImageObserver%29), [prepareImage](../../java/awt/Component.html#prepareImage%28java.awt.Image, int, int, java.awt.image.ImageObserver%29), processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, [removePropertyChangeListener](../../java/awt/Component.html#removePropertyChangeListener%28java.lang.String, java.beans.PropertyChangeListener%29), repaint, [repaint](../../java/awt/Component.html#repaint%28int, int, int, int%29), repaint, resize, [resize](../../java/awt/Component.html#resize%28int, int%29), [setBounds](../../java/awt/Component.html#setBounds%28int, int, int, int%29), setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, [setLocation](../../java/awt/Component.html#setLocation%28int, int%29), setLocation, setName, setSize, [setSize](../../java/awt/Component.html#setSize%28int, int%29), show, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, [wait](../../java/lang/Object.html#wait%28long, int%29) |
Field Detail |
---|
labelFor
protected Component labelFor
Constructor Detail |
---|
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 on the trailing edge 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
,RIGHT
,LEADING
orTRAILING
.
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
,RIGHT
,LEADING
orTRAILING
.
JLabel
public JLabel(String text)
Creates a JLabel
instance with the specified text. The label is aligned against the leading edge 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:
image
- The image to be displayed by the label.
horizontalAlignment
- One of the following constants defined in SwingConstants
:LEFT
,CENTER
, RIGHT
,LEADING
orTRAILING
.
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:
image
- 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 on the leading edge of the label's display area.
Method Detail |
---|
getUI
public LabelUI getUI()
Returns the L&F object that renders this component.
Returns:
LabelUI object
setUI
public void setUI(LabelUI ui)
Sets the L&F object that renders this component.
Parameters:
ui
- the LabelUI L&F object
See Also:
UIDefaults.getUI(javax.swing.JComponent)
updateUI
public void updateUI()
Resets the UI property to a value from the current look and feel.
Overrides:
[updateUI](../../javax/swing/JComponent.html#updateUI%28%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
See Also:
getUIClassID
public String getUIClassID()
Returns a string that specifies the name of the l&f class that renders this component.
Overrides:
[getUIClassID](../../javax/swing/JComponent.html#getUIClassID%28%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
Returns:
String "LabelUI"
See Also:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)
getText
public String getText()
Returns the text string that the label displays.
Returns:
a String
See Also:
setText
public void setText(String text)
Defines the single line of text this component will display. If the value of text is null or empty string, nothing is displayed.
The default value of this property is null.
This is a JavaBeans bound property.
See Also:
setVerticalTextPosition(int), setHorizontalTextPosition(int), setIcon(javax.swing.Icon)
getIcon
public Icon getIcon()
Returns the graphic image (glyph, icon) that the label displays.
Returns:
an Icon
See Also:
setIcon
public void setIcon(Icon icon)
Defines the icon this component will display. If the value of icon is null, nothing is displayed.
The default value of this property is null.
This is a JavaBeans bound property.
See Also:
setVerticalTextPosition(int), setHorizontalTextPosition(int), getIcon()
getDisabledIcon
public Icon getDisabledIcon()
Returns the icon used by the label when it's disabled. If no disabled icon has been set this will forward the call to the look and feel to construct an appropriate disabled Icon.
Some look and feels might not render the disabled Icon, in which case they will ignore this.
Returns:
the disabledIcon
property
See Also:
setDisabledIcon(javax.swing.Icon), [LookAndFeel.getDisabledIcon(javax.swing.JComponent, javax.swing.Icon)](../../javax/swing/LookAndFeel.html#getDisabledIcon%28javax.swing.JComponent, javax.swing.Icon%29), ImageIcon
setDisabledIcon
public void setDisabledIcon(Icon disabledIcon)
Set the icon to be displayed if this JLabel is "disabled" (JLabel.setEnabled(false)).
The default value of this property is null.
Parameters:
disabledIcon
- the Icon to display when the component is disabled
See Also:
getDisabledIcon(), JComponent.setEnabled(boolean)
setDisplayedMnemonic
public void setDisplayedMnemonic(int key)
Specify a keycode that indicates a mnemonic key. This property is used when the label is part of a larger component. If the labelFor property of the label is not null, the label will call the requestFocus method of the component specified by the labelFor property when the mnemonic is activated.
See Also:
getLabelFor(), setLabelFor(java.awt.Component)
setDisplayedMnemonic
public void setDisplayedMnemonic(char aChar)
Specifies the displayedMnemonic as a char value.
Parameters:
aChar
- a char specifying the mnemonic to display
See Also:
getDisplayedMnemonic
public int getDisplayedMnemonic()
Return the keycode that indicates a mnemonic key. This property is used when the label is part of a larger component. If the labelFor property of the label is not null, the label will call the requestFocus method of the component specified by the labelFor property when the mnemonic is activated.
Returns:
int value for the mnemonic key
See Also:
getLabelFor(), setLabelFor(java.awt.Component)
setDisplayedMnemonicIndex
public void setDisplayedMnemonicIndex(int index) throws IllegalArgumentException
Provides a hint to the look and feel as to which character in the text should be decorated to represent the mnemonic. Not all look and feels may support this. A value of -1 indicates either there is no mnemonic, the mnemonic character is not contained in the string, or the developer does not wish the mnemonic to be displayed.
The value of this is updated as the properties relating to the mnemonic change (such as the mnemonic itself, the text...). You should only ever have to call this if you do not wish the default character to be underlined. For example, if the text was 'Save As', with a mnemonic of 'a', and you wanted the 'A' to be decorated, as 'Save As', you would have to invokesetDisplayedMnemonicIndex(5)
after invokingsetMnemonic(KeyEvent.VK_A)
.
Parameters:
index
- Index into the String to underline
Throws:
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- will be thrown if index
= length of the text, or < -1
Since:
1.4
getDisplayedMnemonicIndex
public int getDisplayedMnemonicIndex()
Returns the character, as an index, that the look and feel should provide decoration for as representing the mnemonic character.
Returns:
index representing mnemonic character
Since:
1.4
See Also:
setDisplayedMnemonicIndex(int)
checkHorizontalKey
protected int checkHorizontalKey(int key, String message)
Verify that key is a legal value for the horizontalAlignment properties.
Parameters:
key
- the property value to check
message
- the IllegalArgumentException detail message
Throws:
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if key isn't LEFT, CENTER, RIGHT, LEADING or TRAILING.
See Also:
setHorizontalTextPosition(int), setHorizontalAlignment(int)
checkVerticalKey
protected int checkVerticalKey(int key, String message)
Verify that key is a legal value for the verticalAlignment or verticalTextPosition properties.
Parameters:
key
- the property value to check
message
- the IllegalArgumentException detail message
Throws:
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
- if key isn't TOP, CENTER, or BOTTOM.
See Also:
setVerticalAlignment(int), setVerticalTextPosition(int)
getIconTextGap
public int getIconTextGap()
Returns the amount of space between the text and the icon displayed in this label.
Returns:
an int equal to the number of pixels between the text and the icon.
See Also:
setIconTextGap
public void setIconTextGap(int iconTextGap)
If both the icon and text properties are set, this property defines the space between them.
The default value of this property is 4 pixels.
This is a JavaBeans bound property.
See Also:
getVerticalAlignment
public int getVerticalAlignment()
Returns the alignment of the label's contents along the Y axis.
Returns:
The value of the verticalAlignment property, one of the following constants defined in SwingConstants
:TOP
,CENTER
, orBOTTOM
.
See Also:
SwingConstants, setVerticalAlignment(int)
setVerticalAlignment
public void setVerticalAlignment(int alignment)
Sets the alignment of the label's contents along the Y axis.
The default value of this property is CENTER.
Parameters:
alignment
- One of the following constants defined in SwingConstants
:TOP
,CENTER
(the default), orBOTTOM
.
See Also:
SwingConstants, getVerticalAlignment()
getHorizontalAlignment
public int getHorizontalAlignment()
Returns the alignment of the label's contents along the X axis.
Returns:
The value of the horizontalAlignment property, one of the following constants defined in SwingConstants
:LEFT
,CENTER
, RIGHT
,LEADING
orTRAILING
.
See Also:
setHorizontalAlignment(int), SwingConstants
setHorizontalAlignment
public void setHorizontalAlignment(int alignment)
Sets the alignment of the label's contents along the X axis.
This is a JavaBeans bound property.
Parameters:
alignment
- One of the following constants defined in SwingConstants
:LEFT
,CENTER
(the default for image-only labels),RIGHT
,LEADING
(the default for text-only labels) orTRAILING
.
See Also:
SwingConstants, getHorizontalAlignment()
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
, orBOTTOM
.
See Also:
setVerticalTextPosition(int), SwingConstants
setVerticalTextPosition
public void setVerticalTextPosition(int textPosition)
Sets the vertical position of the label's text, relative to its image.
The default value of this property is CENTER.
This is a JavaBeans bound property.
Parameters:
textPosition
- One of the following constants defined in SwingConstants
:TOP
,CENTER
(the default), orBOTTOM
.
See Also:
SwingConstants, getVerticalTextPosition()
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
, RIGHT
,LEADING
orTRAILING
.
See Also:
setHorizontalTextPosition
public void setHorizontalTextPosition(int textPosition)
Sets the horizontal position of the label's text, relative to its image.
Parameters:
textPosition
- One of the following constants defined in SwingConstants
:LEFT
,CENTER
,RIGHT
,LEADING
, orTRAILING
(the default).
Throws:
[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")
See Also:
imageUpdate
public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
This is overridden to return false if the current Icon's Image is not equal to the passed in Image img
.
Specified by:
[imageUpdate](../../java/awt/image/ImageObserver.html#imageUpdate%28java.awt.Image, int, int, int, int, int%29)
in interface [ImageObserver](../../java/awt/image/ImageObserver.html "interface in java.awt.image")
Overrides:
[imageUpdate](../../java/awt/Component.html#imageUpdate%28java.awt.Image, int, int, int, int, int%29)
in class [Component](../../java/awt/Component.html "class in java.awt")
Parameters:
img
- the image being observed
infoflags
- see imageUpdate
for more information
x
- the x coordinate
y
- the y coordinate
w
- the width
h
- the height
Returns:
false
if the infoflags indicate that the image is completely loaded; true
otherwise.
See Also:
ImageObserver, [Component.imageUpdate(java.awt.Image, int, int, int, int, int)](../../java/awt/Component.html#imageUpdate%28java.awt.Image, int, int, int, int, int%29)
paramString
protected String paramString()
Returns a string representation of this JLabel. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null
.
Overrides:
[paramString](../../javax/swing/JComponent.html#paramString%28%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
Returns:
a string representation of this JLabel.
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. If the displayedMnemonic property is set and the labelFor property is also set, the label will call the requestFocus method of the component specified by the labelFor property when the mnemonic is activated.
See Also:
getDisplayedMnemonic(), setDisplayedMnemonic(int)
setLabelFor
public void setLabelFor(Component c)
Set the component this is labelling. Can be null if this does not label a Component. If the displayedMnemonic property is set and the labelFor property is also set, the label will call the requestFocus method of the component specified by the labelFor property when the mnemonic is activated.
Parameters:
c
- the Component this label is for, or null if the label is not the label for a component
See Also:
getDisplayedMnemonic(), setDisplayedMnemonic(int)
getAccessibleContext
public AccessibleContext getAccessibleContext()
Get the AccessibleContext of this object
Specified by:
[getAccessibleContext](../../javax/accessibility/Accessible.html#getAccessibleContext%28%29)
in interface [Accessible](../../javax/accessibility/Accessible.html "interface in javax.accessibility")
Overrides:
[getAccessibleContext](../../javax/swing/JComponent.html#getAccessibleContext%28%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
Returns:
the AccessibleContext of this object
Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.