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 its ComponentOrientation 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: Swing is not thread safe. For more information see Swing's Threading Policy.
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 JavaBeans™ has been added to the java.beans package. Please see XMLEncoder.
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 its ComponentOrientation 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: Swing is not thread safe. For more information see Swing's Threading Policy. 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 JavaBeans™ has been added to the java.beans package. Please see XMLEncoder.
(->j-label)
(->j-label text)
(->j-label text horizontal-alignment)
(->j-label text icon horizontal-alignment)
Constructor.
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.
text - The text to be displayed by the label. - java.lang.String
icon - The image to be displayed by the label. - javax.swing.Icon
horizontal-alignment - One of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING or TRAILING. - int
Constructor. 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. text - The text to be displayed by the label. - `java.lang.String` icon - The image to be displayed by the label. - `javax.swing.Icon` horizontal-alignment - One of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING or TRAILING. - `int`
(get-accessible-context this)
Get the AccessibleContext of this object
returns: the AccessibleContext of this object - javax.accessibility.AccessibleContext
Get the AccessibleContext of this object returns: the AccessibleContext of this object - `javax.accessibility.AccessibleContext`
(get-disabled-icon this)
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 - javax.swing.Icon
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 - `javax.swing.Icon`
(get-displayed-mnemonic this)
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 - int
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 - `int`
(get-displayed-mnemonic-index this)
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 - int
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 - `int`
(get-horizontal-alignment this)
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 or
TRAILING. - int
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 or TRAILING. - `int`
(get-horizontal-text-position this)
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 or
TRAILING. - int
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 or TRAILING. - `int`
(get-icon this)
Returns the graphic image (glyph, icon) that the label displays.
returns: an Icon - javax.swing.Icon
Returns the graphic image (glyph, icon) that the label displays. returns: an Icon - `javax.swing.Icon`
(get-icon-text-gap this)
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. - int
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. - `int`
(get-label-for this)
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. - java.awt.Component
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. - `java.awt.Component`
(get-text this)
Returns the text string that the label displays.
returns: a String - java.lang.String
Returns the text string that the label displays. returns: a String - `java.lang.String`
(get-ui this)
Returns the L&F object that renders this component.
returns: LabelUI object - javax.swing.plaf.LabelUI
Returns the L&F object that renders this component. returns: LabelUI object - `javax.swing.plaf.LabelUI`
(get-ui-class-id this)
Returns a string that specifies the name of the l&f class that renders this component.
returns: String "LabelUI" - java.lang.String
Returns a string that specifies the name of the l&f class that renders this component. returns: String "LabelUI" - `java.lang.String`
(get-vertical-alignment this)
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, or
BOTTOM. - int
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, or BOTTOM. - `int`
(get-vertical-text-position this)
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. - int
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. - `int`
(image-update this img infoflags x y w h)
This is overridden to return false if the current Icon's Image is not equal to the passed in Image img.
img - the image being observed - java.awt.Image
infoflags - see imageUpdate for more information - int
x - the x coordinate - int
y - the y coordinate - int
w - the width - int
h - the height - int
returns: false if the infoflags indicate that the
image is completely loaded; true otherwise. - boolean
This is overridden to return false if the current Icon's Image is not equal to the passed in Image img. img - the image being observed - `java.awt.Image` infoflags - see imageUpdate for more information - `int` x - the x coordinate - `int` y - the y coordinate - `int` w - the width - `int` h - the height - `int` returns: false if the infoflags indicate that the image is completely loaded; true otherwise. - `boolean`
(set-disabled-icon this disabled-icon)
Set the icon to be displayed if this JLabel is "disabled" (JLabel.setEnabled(false)).
The default value of this property is null.
disabled-icon - the Icon to display when the component is disabled - javax.swing.Icon
Set the icon to be displayed if this JLabel is "disabled" (JLabel.setEnabled(false)). The default value of this property is null. disabled-icon - the Icon to display when the component is disabled - `javax.swing.Icon`
(set-displayed-mnemonic this 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.
key - int
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. key - `int`
(set-displayed-mnemonic-index this index)
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 invoke setDisplayedMnemonicIndex(5) after invoking setDisplayedMnemonic(KeyEvent.VK_A).
index - Index into the String to underline - int
throws: java.lang.IllegalArgumentException - will be thrown if index is >= length of the text, or < -1
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 invoke setDisplayedMnemonicIndex(5) after invoking setDisplayedMnemonic(KeyEvent.VK_A). index - Index into the String to underline - `int` throws: java.lang.IllegalArgumentException - will be thrown if index is >= length of the text, or < -1
(set-horizontal-alignment this alignment)
Sets the alignment of the label's contents along the X axis.
This is a JavaBeans bound property.
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) or TRAILING. - int
Sets the alignment of the label's contents along the X axis. This is a JavaBeans bound property. 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) or TRAILING. - `int`
(set-horizontal-text-position this text-position)
Sets the horizontal position of the label's text, relative to its image.
text-position - One of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING, or TRAILING (the default). - int
throws: java.lang.IllegalArgumentException
Sets the horizontal position of the label's text, relative to its image. text-position - One of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING, or TRAILING (the default). - `int` throws: java.lang.IllegalArgumentException
(set-icon this 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.
icon - javax.swing.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. icon - `javax.swing.Icon`
(set-icon-text-gap this icon-text-gap)
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.
icon-text-gap - int
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. icon-text-gap - `int`
(set-label-for this 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.
c - the Component this label is for, or null if the label is not the label for a component - java.awt.Component
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. c - the Component this label is for, or null if the label is not the label for a component - `java.awt.Component`
(set-text this 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.
text - java.lang.String
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. text - `java.lang.String`
(set-ui this ui)
Sets the L&F object that renders this component.
ui - the LabelUI L&F object - javax.swing.plaf.LabelUI
Sets the L&F object that renders this component. ui - the LabelUI L&F object - `javax.swing.plaf.LabelUI`
(set-vertical-alignment this alignment)
Sets the alignment of the label's contents along the Y axis.
The default value of this property is CENTER.
alignment - One of the following constants defined in SwingConstants: TOP, CENTER (the default), or BOTTOM. - int
Sets the alignment of the label's contents along the Y axis. The default value of this property is CENTER. alignment - One of the following constants defined in SwingConstants: TOP, CENTER (the default), or BOTTOM. - `int`
(set-vertical-text-position this text-position)
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.
text-position - One of the following constants defined in SwingConstants: TOP, CENTER (the default), or BOTTOM. - int
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. text-position - One of the following constants defined in SwingConstants: TOP, CENTER (the default), or BOTTOM. - `int`
(update-ui this)
Resets the UI property to a value from the current look and feel.
Resets the UI property to a value from the current look and feel.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close