< prev index next >
src/java.desktop/share/classes/javax/swing/JLabel.java
Print this page
*** 52,62 ****
* 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.
* <p>
! * A <code>JLabel</code> 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
--- 52,62 ----
* 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.
* <p>
! * A {@code 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
*** 73,83 ****
* {@link java.awt.ComponentOrientation} property. At present, the default
* ComponentOrientation setting maps the leading edge to left and the trailing
* edge to right.
*
* <p>
! * Finally, you can use the <code>setIconTextGap</code> method
* to specify how many pixels
* should appear between the text and the image.
* The default is 4 pixels.
* <p>
* See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/label.html">How to Use Labels</a>
--- 73,83 ----
* {@link java.awt.ComponentOrientation} property. At present, the default
* ComponentOrientation setting maps the leading edge to left and the trailing
* edge to right.
*
* <p>
! * Finally, you can use the {@code setIconTextGap} method
* to specify how many pixels
* should appear between the text and the image.
* The default is 4 pixels.
* <p>
* See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/label.html">How to Use Labels</a>
*** 93,103 ****
* 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 <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*
* @beaninfo
* attribute: isContainer false
* description: A component that displays a short string and an icon.
--- 93,103 ----
* 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 {@code java.beans} package.
* Please see {@link java.beans.XMLEncoder}.
*
* @beaninfo
* attribute: isContainer false
* description: A component that displays a short string and an icon.
*** 145,237 ****
* @see #setLabelFor
*/
static final String LABELED_BY_PROPERTY = "labeledBy";
/**
! * Creates a <code>JLabel</code> 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.
*
* @param text The text to be displayed by the label.
* @param icon The image to be displayed by the label.
* @param horizontalAlignment One of the following constants
! * defined in <code>SwingConstants</code>:
! * <code>LEFT</code>,
! * <code>CENTER</code>,
! * <code>RIGHT</code>,
! * <code>LEADING</code> or
! * <code>TRAILING</code>.
*/
public JLabel(String text, Icon icon, int horizontalAlignment) {
setText(text);
setIcon(icon);
setHorizontalAlignment(horizontalAlignment);
updateUI();
setAlignmentX(LEFT_ALIGNMENT);
}
/**
! * Creates a <code>JLabel</code> instance with the specified
* text and horizontal alignment.
* The label is centered vertically in its display area.
*
* @param text The text to be displayed by the label.
* @param horizontalAlignment One of the following constants
! * defined in <code>SwingConstants</code>:
! * <code>LEFT</code>,
! * <code>CENTER</code>,
! * <code>RIGHT</code>,
! * <code>LEADING</code> or
! * <code>TRAILING</code>.
*/
public JLabel(String text, int horizontalAlignment) {
this(text, null, horizontalAlignment);
}
/**
! * Creates a <code>JLabel</code> instance with the specified text.
* The label is aligned against the leading edge of its display area,
* and centered vertically.
*
* @param text The text to be displayed by the label.
*/
public JLabel(String text) {
this(text, null, LEADING);
}
/**
! * Creates a <code>JLabel</code> instance with the specified
* image and horizontal alignment.
* The label is centered vertically in its display area.
*
* @param image The image to be displayed by the label.
* @param horizontalAlignment One of the following constants
! * defined in <code>SwingConstants</code>:
! * <code>LEFT</code>,
! * <code>CENTER</code>,
! * <code>RIGHT</code>,
! * <code>LEADING</code> or
! * <code>TRAILING</code>.
*/
public JLabel(Icon image, int horizontalAlignment) {
this(null, image, horizontalAlignment);
}
/**
! * Creates a <code>JLabel</code> instance with the specified image.
* The label is centered vertically and horizontally
* in its display area.
*
* @param image The image to be displayed by the label.
*/
public JLabel(Icon image) {
this(null, image, CENTER);
}
/**
! * Creates a <code>JLabel</code> 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.
--- 145,237 ----
* @see #setLabelFor
*/
static final String LABELED_BY_PROPERTY = "labeledBy";
/**
! * Creates a {@code 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.
*
* @param text The text to be displayed by the label.
* @param icon The image to be displayed by the label.
* @param horizontalAlignment One of the following constants
! * defined in {@code SwingConstants}:
! * {@code LEFT},
! * {@code CENTER},
! * {@code RIGHT},
! * {@code LEADING} or
! * {@code TRAILING}.
*/
public JLabel(String text, Icon icon, int horizontalAlignment) {
setText(text);
setIcon(icon);
setHorizontalAlignment(horizontalAlignment);
updateUI();
setAlignmentX(LEFT_ALIGNMENT);
}
/**
! * Creates a {@code JLabel} instance with the specified
* text and horizontal alignment.
* The label is centered vertically in its display area.
*
* @param text The text to be displayed by the label.
* @param horizontalAlignment One of the following constants
! * defined in {@code SwingConstants}:
! * {@code LEFT},
! * {@code CENTER},
! * {@code RIGHT},
! * {@code LEADING} or
! * {@code TRAILING}.
*/
public JLabel(String text, int horizontalAlignment) {
this(text, null, horizontalAlignment);
}
/**
! * Creates a {@code JLabel} instance with the specified text.
* The label is aligned against the leading edge of its display area,
* and centered vertically.
*
* @param text The text to be displayed by the label.
*/
public JLabel(String text) {
this(text, null, LEADING);
}
/**
! * Creates a {@code JLabel} instance with the specified
* image and horizontal alignment.
* The label is centered vertically in its display area.
*
* @param image The image to be displayed by the label.
* @param horizontalAlignment One of the following constants
! * defined in {@code SwingConstants}:
! * {@code LEFT},
! * {@code CENTER},
! * {@code RIGHT},
! * {@code LEADING} or
! * {@code TRAILING}.
*/
public JLabel(Icon image, int horizontalAlignment) {
this(null, image, horizontalAlignment);
}
/**
! * Creates a {@code JLabel} instance with the specified image.
* The label is centered vertically and horizontally
* in its display area.
*
* @param image The image to be displayed by the label.
*/
public JLabel(Icon image) {
this(null, image, CENTER);
}
/**
! * Creates a {@code 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.
*** 424,434 ****
* the look and feel to construct an appropriate disabled Icon.
* <p>
* Some look and feels might not render the disabled Icon, in which
* case they will ignore this.
*
! * @return the <code>disabledIcon</code> property
* @see #setDisabledIcon
* @see javax.swing.LookAndFeel#getDisabledIcon
* @see ImageIcon
*/
@Transient
--- 424,434 ----
* the look and feel to construct an appropriate disabled Icon.
* <p>
* Some look and feels might not render the disabled Icon, in which
* case they will ignore this.
*
! * @return the {@code disabledIcon} property
* @see #setDisabledIcon
* @see javax.swing.LookAndFeel#getDisabledIcon
* @see ImageIcon
*/
@Transient
*** 546,561 ****
* 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 <u>A</u>s', you would have to invoke
! * <code>setDisplayedMnemonicIndex(5)</code> after invoking
! * <code>setDisplayedMnemonic(KeyEvent.VK_A)</code>.
*
* @since 1.4
* @param index Index into the String to underline
! * @exception IllegalArgumentException will be thrown if <code>index</code>
* is >= length of the text, or < -1
*
* @beaninfo
* bound: true
* attribute: visualUpdate true
--- 546,561 ----
* 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 <u>A</u>s', you would have to invoke
! * {@code setDisplayedMnemonicIndex(5)} after invoking
! * {@code setDisplayedMnemonic(KeyEvent.VK_A)}.
*
* @since 1.4
* @param index Index into the String to underline
! * @exception IllegalArgumentException will be thrown if {@code index}
* is >= length of the text, or < -1
*
* @beaninfo
* bound: true
* attribute: visualUpdate true
*** 685,698 ****
/**
* Returns the alignment of the label's contents along the Y axis.
*
* @return The value of the verticalAlignment property, one of the
! * following constants defined in <code>SwingConstants</code>:
! * <code>TOP</code>,
! * <code>CENTER</code>, or
! * <code>BOTTOM</code>.
*
* @see SwingConstants
* @see #setVerticalAlignment
*/
public int getVerticalAlignment() {
--- 685,698 ----
/**
* Returns the alignment of the label's contents along the Y axis.
*
* @return The value of the verticalAlignment property, one of the
! * following constants defined in {@code SwingConstants}:
! * {@code TOP},
! * {@code CENTER}, or
! * {@code BOTTOM}.
*
* @see SwingConstants
* @see #setVerticalAlignment
*/
public int getVerticalAlignment() {
*** 704,717 ****
* Sets the alignment of the label's contents along the Y axis.
* <p>
* The default value of this property is CENTER.
*
* @param alignment One of the following constants
! * defined in <code>SwingConstants</code>:
! * <code>TOP</code>,
! * <code>CENTER</code> (the default), or
! * <code>BOTTOM</code>.
*
* @see SwingConstants
* @see #getVerticalAlignment
* @beaninfo
* bound: true
--- 704,717 ----
* Sets the alignment of the label's contents along the Y axis.
* <p>
* The default value of this property is CENTER.
*
* @param alignment One of the following constants
! * defined in {@code SwingConstants}:
! * {@code TOP},
! * {@code CENTER} (the default), or
! * {@code BOTTOM}.
*
* @see SwingConstants
* @see #getVerticalAlignment
* @beaninfo
* bound: true
*** 732,747 ****
/**
* Returns the alignment of the label's contents along the X axis.
*
* @return The value of the horizontalAlignment property, one of the
! * following constants defined in <code>SwingConstants</code>:
! * <code>LEFT</code>,
! * <code>CENTER</code>,
! * <code>RIGHT</code>,
! * <code>LEADING</code> or
! * <code>TRAILING</code>.
*
* @see #setHorizontalAlignment
* @see SwingConstants
*/
public int getHorizontalAlignment() {
--- 732,747 ----
/**
* Returns the alignment of the label's contents along the X axis.
*
* @return The value of the horizontalAlignment property, one of the
! * following constants defined in {@code SwingConstants}:
! * {@code LEFT},
! * {@code CENTER},
! * {@code RIGHT},
! * {@code LEADING} or
! * {@code TRAILING}.
*
* @see #setHorizontalAlignment
* @see SwingConstants
*/
public int getHorizontalAlignment() {
*** 752,767 ****
* Sets the alignment of the label's contents along the X axis.
* <p>
* This is a JavaBeans bound property.
*
* @param alignment One of the following constants
! * defined in <code>SwingConstants</code>:
! * <code>LEFT</code>,
! * <code>CENTER</code> (the default for image-only labels),
! * <code>RIGHT</code>,
! * <code>LEADING</code> (the default for text-only labels) or
! * <code>TRAILING</code>.
*
* @see SwingConstants
* @see #getHorizontalAlignment
* @beaninfo
* bound: true
--- 752,767 ----
* Sets the alignment of the label's contents along the X axis.
* <p>
* This is a JavaBeans bound property.
*
* @param alignment One of the following constants
! * defined in {@code SwingConstants}:
! * {@code LEFT},
! * {@code CENTER} (the default for image-only labels),
! * {@code RIGHT},
! * {@code LEADING} (the default for text-only labels) or
! * {@code TRAILING}.
*
* @see SwingConstants
* @see #getHorizontalAlignment
* @beaninfo
* bound: true
*** 787,800 ****
/**
* Returns the vertical position of the label's text,
* relative to its image.
*
* @return One of the following constants
! * defined in <code>SwingConstants</code>:
! * <code>TOP</code>,
! * <code>CENTER</code>, or
! * <code>BOTTOM</code>.
*
* @see #setVerticalTextPosition
* @see SwingConstants
*/
public int getVerticalTextPosition() {
--- 787,800 ----
/**
* Returns the vertical position of the label's text,
* relative to its image.
*
* @return One of the following constants
! * defined in {@code SwingConstants}:
! * {@code TOP},
! * {@code CENTER}, or
! * {@code BOTTOM}.
*
* @see #setVerticalTextPosition
* @see SwingConstants
*/
public int getVerticalTextPosition() {
*** 809,822 ****
* The default value of this property is CENTER.
* <p>
* This is a JavaBeans bound property.
*
* @param textPosition One of the following constants
! * defined in <code>SwingConstants</code>:
! * <code>TOP</code>,
! * <code>CENTER</code> (the default), or
! * <code>BOTTOM</code>.
*
* @see SwingConstants
* @see #getVerticalTextPosition
* @beaninfo
* bound: true
--- 809,822 ----
* The default value of this property is CENTER.
* <p>
* This is a JavaBeans bound property.
*
* @param textPosition One of the following constants
! * defined in {@code SwingConstants}:
! * {@code TOP},
! * {@code CENTER} (the default), or
! * {@code BOTTOM}.
*
* @see SwingConstants
* @see #getVerticalTextPosition
* @beaninfo
* bound: true
*** 841,856 ****
/**
* Returns the horizontal position of the label's text,
* relative to its image.
*
* @return One of the following constants
! * defined in <code>SwingConstants</code>:
! * <code>LEFT</code>,
! * <code>CENTER</code>,
! * <code>RIGHT</code>,
! * <code>LEADING</code> or
! * <code>TRAILING</code>.
*
* @see SwingConstants
*/
public int getHorizontalTextPosition() {
return horizontalTextPosition;
--- 841,856 ----
/**
* Returns the horizontal position of the label's text,
* relative to its image.
*
* @return One of the following constants
! * defined in {@code SwingConstants}:
! * {@code LEFT},
! * {@code CENTER},
! * {@code RIGHT},
! * {@code LEADING} or
! * {@code TRAILING}.
*
* @see SwingConstants
*/
public int getHorizontalTextPosition() {
return horizontalTextPosition;
*** 860,875 ****
/**
* Sets the horizontal position of the label's text,
* relative to its image.
*
* @param textPosition One of the following constants
! * defined in <code>SwingConstants</code>:
! * <code>LEFT</code>,
! * <code>CENTER</code>,
! * <code>RIGHT</code>,
! * <code>LEADING</code>, or
! * <code>TRAILING</code> (the default).
*
* @see SwingConstants
* @beaninfo
* expert: true
* bound: true
--- 860,875 ----
/**
* Sets the horizontal position of the label's text,
* relative to its image.
*
* @param textPosition One of the following constants
! * defined in {@code SwingConstants}:
! * {@code LEFT},
! * {@code CENTER},
! * {@code RIGHT},
! * {@code LEADING}, or
! * {@code TRAILING} (the default).
*
* @see SwingConstants
* @beaninfo
* expert: true
* bound: true
*** 893,903 ****
}
/**
* This is overridden to return false if the current Icon's Image is
! * not equal to the passed in Image <code>img</code>.
*
* @see java.awt.image.ImageObserver
* @see java.awt.Component#imageUpdate(java.awt.Image, int, int, int, int, int)
*/
public boolean imageUpdate(Image img, int infoflags,
--- 893,903 ----
}
/**
* This is overridden to return false if the current Icon's Image is
! * not equal to the passed in Image {@code img}.
*
* @see java.awt.image.ImageObserver
* @see java.awt.Component#imageUpdate(java.awt.Image, int, int, int, int, int)
*/
public boolean imageUpdate(Image img, int infoflags,
*** 933,943 ****
/**
* 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 <code>null</code>.
*
* @return a string representation of this JLabel.
*/
protected String paramString() {
String textString = (text != null ?
--- 933,943 ----
/**
* 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 {@code null}.
*
* @return a string representation of this JLabel.
*/
protected String paramString() {
String textString = (text != null ?
*** 1075,1085 ****
* 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 <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*/
@SuppressWarnings("serial")
protected class AccessibleJLabel extends AccessibleJComponent
implements AccessibleText, AccessibleExtendedComponent {
--- 1075,1085 ----
* 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 {@code java.beans} package.
* Please see {@link java.beans.XMLEncoder}.
*/
@SuppressWarnings("serial")
protected class AccessibleJLabel extends AccessibleJComponent
implements AccessibleText, AccessibleExtendedComponent {
*** 1197,1211 ****
}
/**
* Returns the bounding box of the character at the given
* index in the string. The bounds are returned in local
! * coordinates. If the index is invalid, <code>null</code> is returned.
*
* @param i the index into the String
* @return the screen coordinates of the character's bounding box.
! * If the index is invalid, <code>null</code> is returned.
* @since 1.3
*/
public Rectangle getCharacterBounds(int i) {
View view = (View) JLabel.this.getClientProperty("html");
if (view != null) {
--- 1197,1211 ----
}
/**
* Returns the bounding box of the character at the given
* index in the string. The bounds are returned in local
! * coordinates. If the index is invalid, {@code null} is returned.
*
* @param i the index into the String
* @return the screen coordinates of the character's bounding box.
! * If the index is invalid, {@code null} is returned.
* @since 1.3
*/
public Rectangle getCharacterBounds(int i) {
View view = (View) JLabel.this.getClientProperty("html");
if (view != null) {
*** 1615,1636 ****
* Returns a key binding for this object. The value returned is an
* java.lang.Object which must be cast to appropriate type depending
* on the underlying implementation of the key. For example, if the
* Object returned is a javax.swing.KeyStroke, the user of this
* method should do the following:
! * <nf><code>
* Component c = <get the component that has the key bindings>
* AccessibleContext ac = c.getAccessibleContext();
* AccessibleKeyBinding akb = ac.getAccessibleKeyBinding();
* for (int i = 0; i < akb.getAccessibleKeyBindingCount(); i++) {
* Object o = akb.getAccessibleKeyBinding(i);
* if (o instanceof javax.swing.KeyStroke) {
* javax.swing.KeyStroke keyStroke = (javax.swing.KeyStroke)o;
* <do something with the key binding>
* }
* }
! * </code></nf>
*
* @param i zero-based index of the key bindings
* @return a javax.lang.Object which specifies the key binding
* @exception IllegalArgumentException if the index is
* out of bounds
--- 1615,1636 ----
* Returns a key binding for this object. The value returned is an
* java.lang.Object which must be cast to appropriate type depending
* on the underlying implementation of the key. For example, if the
* Object returned is a javax.swing.KeyStroke, the user of this
* method should do the following:
! * <pre>{@code
* Component c = <get the component that has the key bindings>
* AccessibleContext ac = c.getAccessibleContext();
* AccessibleKeyBinding akb = ac.getAccessibleKeyBinding();
* for (int i = 0; i < akb.getAccessibleKeyBindingCount(); i++) {
* Object o = akb.getAccessibleKeyBinding(i);
* if (o instanceof javax.swing.KeyStroke) {
* javax.swing.KeyStroke keyStroke = (javax.swing.KeyStroke)o;
* <do something with the key binding>
* }
* }
! * }</pre>
*
* @param i zero-based index of the key bindings
* @return a javax.lang.Object which specifies the key binding
* @exception IllegalArgumentException if the index is
* out of bounds
< prev index next >