[cp-patches] FYI: JLabel fixes

David Gilbert david.gilbert at object-refinery.com
Mon May 22 19:52:28 UTC 2006


This patch (committed) fixes a couple of small bugs in JLabel.  The 
getAccessibleName() method needs to be overridden to return the label text if it is 
defined.  The setLabelFor() is firing PropertyChangeEvents in a different order to 
the reference implementation:

2006-05-22  David Gilbert  <david.gilbert at object-refinery.com>

	* javax/swing/JLabel.java
	(AccessibleJLabel.getAccessibleName): New method (override),
	(setLabelFor): Fire 'labelFor' property change event before other
	events.

Regards,

Dave
-------------- next part --------------
Index: javax/swing/JLabel.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/JLabel.java,v
retrieving revision 1.34
diff -u -r1.34 JLabel.java
--- javax/swing/JLabel.java	22 May 2006 16:02:20 -0000	1.34
+++ javax/swing/JLabel.java	22 May 2006 19:48:53 -0000
@@ -72,6 +72,19 @@
   {
     
     /**
+     * Returns the accessible name.
+     * 
+     * @return The accessible name.
+     */
+    public String getAccessibleName()
+    {
+      if (text != null)
+        return text;
+      else
+        return super.getAccessibleName();
+    }
+    
+    /**
      * Returns the accessible role for the <code>JLabel</code> component.
      *
      * @return {@link AccessibleRole#LABEL}.
@@ -908,24 +921,25 @@
   {
     if (c != labelFor)
       {
+        Component oldLabelFor = labelFor;
+        labelFor = c;
+        firePropertyChange("labelFor", oldLabelFor, labelFor);
+
         // We put the label into the client properties for the labeled
         // component so that it can be read by the AccessibleJComponent.
         // The other option would be to reserve a default visible field
-        // in JComponent, but since this is relativly seldomly used, it
+        // in JComponent, but since this is relatively seldomly used, it
         // would be unnecessary waste of memory to do so.
-	Component oldLabelFor = labelFor;
         if (oldLabelFor instanceof JComponent)
           {
             ((JComponent) oldLabelFor).putClientProperty(LABEL_PROPERTY, null);
           }
 
-	labelFor = c;
-	if (labelFor instanceof JComponent)
+        if (labelFor instanceof JComponent)
           {
             ((JComponent) labelFor).putClientProperty(LABEL_PROPERTY, this);
           }
 
-	firePropertyChange("labelFor", oldLabelFor, labelFor);
       }
   }
 


More information about the Classpath-patches mailing list