src/java.desktop/share/classes/javax/swing/JLabel.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -20,32 +20,27 @@
  *
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
-
 package javax.swing;
 
 import java.awt.Component;
-import java.awt.Font;
 import java.awt.Image;
 import java.awt.*;
 import java.text.*;
 import java.awt.geom.*;
+import java.beans.JavaBean;
+import java.beans.BeanProperty;
 import java.beans.Transient;
 
 import java.io.ObjectOutputStream;
-import java.io.ObjectInputStream;
 import java.io.IOException;
 
 import javax.swing.plaf.LabelUI;
 import javax.accessibility.*;
 import javax.swing.text.*;
-import javax.swing.text.html.*;
-import javax.swing.plaf.basic.*;
-import java.util.*;
-
 
 /**
  * A display area for a short text string or an image,
  * or both.
  * A label does not react to input events.

@@ -96,17 +91,15 @@
  * 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.
- *
  * @author Hans Muller
  * @since 1.2
  */
+@JavaBean(defaultProperty = "UI", description = "A component that displays a short string and an icon.")
+@SwingContainer(false)
 @SuppressWarnings("serial")
 public class JLabel extends JComponent implements SwingConstants, Accessible
 {
     /**
      * @see #getUIClassID

@@ -254,16 +247,13 @@
     /**
      * Sets the L&amp;F object that renders this component.
      *
      * @param ui  the LabelUI L&amp;F object
      * @see UIDefaults#getUI
-     * @beaninfo
-     *        bound: true
-     *       hidden: true
-     *    attribute: visualUpdate true
-     *  description: The UI object that implements the Component's LookAndFeel.
      */
+    @BeanProperty(hidden = true, visualUpdate = true, description
+            = "The UI object that implements the Component's LookAndFeel.")
     public void setUI(LabelUI ui) {
         super.setUI(ui);
         // disabled icon is generated by LF so it should be unset here
         if (!disabledIconSet && disabledIcon != null) {
             setDisabledIcon(null);

@@ -275,11 +265,11 @@
      * Resets the UI property to a value from the current look and feel.
      *
      * @see JComponent#updateUI
      */
     public void updateUI() {
-        setUI((LabelUI)UIManager.getUI(this));
+        setUI((LabelUI) UIManager.getUI(this));
     }
 
 
     /**
      * Returns a string that specifies the name of the l&amp;f class

@@ -288,10 +278,11 @@
      * @return String "LabelUI"
      *
      * @see JComponent#getUIClassID
      * @see UIDefaults#getUI
      */
+    @BeanProperty(bound = false)
     public String getUIClassID() {
         return uiClassID;
     }
 
 

@@ -316,16 +307,13 @@
      *
      * @param text  the single line of text this component will display
      * @see #setVerticalTextPosition
      * @see #setHorizontalTextPosition
      * @see #setIcon
-     * @beaninfo
-     *    preferred: true
-     *        bound: true
-     *    attribute: visualUpdate true
-     *  description: Defines the single line of text this component will display.
      */
+    @BeanProperty(preferred = true, visualUpdate = true, description
+            = "Defines the single line of text this component will display.")
     public void setText(String text) {
 
         String oldAccessibleName = null;
         if (accessibleContext != null) {
             oldAccessibleName = accessibleContext.getAccessibleName();

@@ -373,16 +361,13 @@
      *
      * @param icon  the default icon this component will display
      * @see #setVerticalTextPosition
      * @see #setHorizontalTextPosition
      * @see #getIcon
-     * @beaninfo
-     *    preferred: true
-     *        bound: true
-     *    attribute: visualUpdate true
-     *  description: The icon this component will display.
      */
+    @BeanProperty(preferred = true, visualUpdate = true, description
+            = "The icon this component will display.")
     public void setIcon(Icon icon) {
         Icon oldValue = defaultIcon;
         defaultIcon = icon;
 
         /* If the default icon has really changed and we had

@@ -450,15 +435,13 @@
      * The default value of this property is null.
      *
      * @param disabledIcon the Icon to display when the component is disabled
      * @see #getDisabledIcon
      * @see #setEnabled
-     * @beaninfo
-     *        bound: true
-     *    attribute: visualUpdate true
-     *  description: The icon to display if the label is disabled.
      */
+    @BeanProperty(visualUpdate = true, description
+            = "The icon to display if the label is disabled.")
     public void setDisabledIcon(Icon disabledIcon) {
         Icon oldValue = this.disabledIcon;
         this.disabledIcon = disabledIcon;
         disabledIconSet = (disabledIcon != null);
         firePropertyChange("disabledIcon", oldValue, disabledIcon);

@@ -483,15 +466,13 @@
      * labelFor property when the mnemonic is activated.
      *
      * @param key  a keycode that indicates a mnemonic key
      * @see #getLabelFor
      * @see #setLabelFor
-     * @beaninfo
-     *        bound: true
-     *    attribute: visualUpdate true
-     *  description: The mnemonic keycode.
      */
+    @BeanProperty(visualUpdate = true, description
+            = "The mnemonic keycode.")
     public void setDisplayedMnemonic(int key) {
         int oldKey = mnemonic;
         mnemonic = key;
         firePropertyChange("displayedMnemonic", oldKey, mnemonic);
 

@@ -553,17 +534,13 @@
      *
      * @since 1.4
      * @param index Index into the String to underline
      * @exception IllegalArgumentException will be thrown if <code>index</code>
      *            is &gt;= length of the text, or &lt; -1
-     *
-     * @beaninfo
-     *        bound: true
-     *    attribute: visualUpdate true
-     *  description: the index into the String to draw the keyboard character
-     *               mnemonic at
      */
+    @BeanProperty(visualUpdate = true, description
+            = "the index into the String to draw the keyboard character mnemonic at")
     public void setDisplayedMnemonicIndex(int index)
                                              throws IllegalArgumentException {
         int oldValue = mnemonicIndex;
         if (index == -1) {
             mnemonicIndex = -1;

@@ -663,16 +640,13 @@
      * <p>
      * This is a JavaBeans bound property.
      *
      * @param iconTextGap  the space between the icon and text properties
      * @see #getIconTextGap
-     * @beaninfo
-     *        bound: true
-     *    attribute: visualUpdate true
-     *  description: If both the icon and text properties are set, this
-     *               property defines the space between them.
      */
+    @BeanProperty(visualUpdate = true, description
+            = "If both the icon and text properties are set, this property defines the space between them.")
     public void setIconTextGap(int iconTextGap) {
         int oldValue = this.iconTextGap;
         this.iconTextGap = iconTextGap;
         firePropertyChange("iconTextGap", oldValue, iconTextGap);
         if (iconTextGap != oldValue) {

@@ -711,18 +685,16 @@
      *           <code>CENTER</code> (the default), or
      *           <code>BOTTOM</code>.
      *
      * @see SwingConstants
      * @see #getVerticalAlignment
-     * @beaninfo
-     *        bound: true
-     *         enum: TOP    SwingConstants.TOP
-     *               CENTER SwingConstants.CENTER
-     *               BOTTOM SwingConstants.BOTTOM
-     *    attribute: visualUpdate true
-     *  description: The alignment of the label's contents along the Y axis.
      */
+    @BeanProperty(visualUpdate = true, enumerationValues = {
+            "SwingConstants.TOP",
+            "SwingConstants.CENTER",
+            "SwingConstants.BOTTOM"},
+            description = "The alignment of the label's contents along the Y axis.")
     public void setVerticalAlignment(int alignment) {
         if (alignment == verticalAlignment) return;
         int oldValue = verticalAlignment;
         verticalAlignment = checkVerticalKey(alignment, "verticalAlignment");
         firePropertyChange("verticalAlignment", oldValue, verticalAlignment);

@@ -761,20 +733,18 @@
      *           <code>LEADING</code> (the default for text-only labels) or
      *           <code>TRAILING</code>.
      *
      * @see SwingConstants
      * @see #getHorizontalAlignment
-     * @beaninfo
-     *        bound: true
-     *         enum: LEFT     SwingConstants.LEFT
-     *               CENTER   SwingConstants.CENTER
-     *               RIGHT    SwingConstants.RIGHT
-     *               LEADING  SwingConstants.LEADING
-     *               TRAILING SwingConstants.TRAILING
-     *    attribute: visualUpdate true
-     *  description: The alignment of the label's content along the X axis.
      */
+    @BeanProperty(visualUpdate = true, enumerationValues = {
+            "SwingConstants.LEFT",
+            "SwingConstants.CENTER",
+            "SwingConstants.RIGHT",
+            "SwingConstants.LEADING",
+            "SwingConstants.TRAILING"}, description
+            = "The alignment of the label's content along the X axis.")
     public void setHorizontalAlignment(int alignment) {
         if (alignment == horizontalAlignment) return;
         int oldValue = horizontalAlignment;
         horizontalAlignment = checkHorizontalKey(alignment,
                                                  "horizontalAlignment");

@@ -816,19 +786,16 @@
      *           <code>CENTER</code> (the default), or
      *           <code>BOTTOM</code>.
      *
      * @see SwingConstants
      * @see #getVerticalTextPosition
-     * @beaninfo
-     *        bound: true
-     *         enum: TOP    SwingConstants.TOP
-     *               CENTER SwingConstants.CENTER
-     *               BOTTOM SwingConstants.BOTTOM
-     *       expert: true
-     *    attribute: visualUpdate true
-     *  description: The vertical position of the text relative to it's image.
      */
+    @BeanProperty(expert = true, visualUpdate = true, enumerationValues = {
+            "SwingConstants.TOP",
+            "SwingConstants.CENTER",
+            "SwingConstants.BOTTOM"},
+            description = "The vertical position of the text relative to it's image.")
     public void setVerticalTextPosition(int textPosition) {
         if (textPosition == verticalTextPosition) return;
         int old = verticalTextPosition;
         verticalTextPosition = checkVerticalKey(textPosition,
                                                 "verticalTextPosition");

@@ -868,22 +835,18 @@
      *           <code>RIGHT</code>,
      *           <code>LEADING</code>, or
      *           <code>TRAILING</code> (the default).
      *
      * @see SwingConstants
-     * @beaninfo
-     *       expert: true
-     *        bound: true
-     *         enum: LEFT     SwingConstants.LEFT
-     *               CENTER   SwingConstants.CENTER
-     *               RIGHT    SwingConstants.RIGHT
-     *               LEADING  SwingConstants.LEADING
-     *               TRAILING SwingConstants.TRAILING
-     *    attribute: visualUpdate true
-     *  description: The horizontal position of the label's text,
-     *               relative to its image.
      */
+    @BeanProperty(expert = true, visualUpdate = true, enumerationValues = {
+            "SwingConstants.LEFT",
+            "SwingConstants.CENTER",
+            "SwingConstants.RIGHT",
+            "SwingConstants.LEADING",
+            "SwingConstants.TRAILING"}, description
+            = "The horizontal position of the label's text, relative to its image.")
     public void setHorizontalTextPosition(int textPosition) {
         int old = horizontalTextPosition;
         this.horizontalTextPosition = checkHorizontalKey(textPosition,
                                                 "horizontalTextPosition");
         firePropertyChange("horizontalTextPosition",

@@ -1033,15 +996,13 @@
      * @param c  the Component this label is for, or null if the label is
      *           not the label for a component
      *
      * @see #getDisplayedMnemonic
      * @see #setDisplayedMnemonic
-     *
-     * @beaninfo
-     *        bound: true
-     *  description: The component this is labelling.
      */
+    @BeanProperty(description
+            = "The component this is labelling.")
     public void setLabelFor(Component c) {
         Component oldC = labelFor;
         labelFor = c;
         firePropertyChange("labelFor", oldC, c);
 

@@ -1055,14 +1016,13 @@
 
     /**
      * Get the AccessibleContext of this object
      *
      * @return the AccessibleContext of this object
-     * @beaninfo
-     *       expert: true
-     *  description: The AccessibleContext associated with this Label.
      */
+    @BeanProperty(bound = false, expert = true, description
+            = "The AccessibleContext associated with this Label.")
     public AccessibleContext getAccessibleContext() {
         if (accessibleContext == null) {
             accessibleContext = new AccessibleJLabel();
         }
         return accessibleContext;