src/share/classes/java/awt/Component.java

Print this page

        

@@ -9064,10 +9064,19 @@
         private volatile transient int propertyListenersCount = 0;
 
         protected ComponentListener accessibleAWTComponentHandler = null;
         protected FocusListener accessibleAWTFocusHandler = null;
 
+        // accessibleAWTFocusHandler can be set either from
+        // JComponent.AccessibleJComponent.addPropertyChangeListener or from this
+        // object's addPropertyChangeListener the first time that method is called
+        // if accessibleAWTFocusHandler is null at the time of the call.  In the
+        // former case Component.addFocusListener has already been called so it
+        // should not be called again in this object's addPropertyChangeListener.
+        // Also, removeFocusListener should only be called if this boolean is set.
+        boolean focusHandlerSetFromComponent = false;
+
         /**
          * Fire PropertyChange listener, if one is registered,
          * when shown/hidden..
          * @since 1.3
          */

@@ -9127,16 +9136,19 @@
         public void addPropertyChangeListener(PropertyChangeListener listener) {
             if (accessibleAWTComponentHandler == null) {
                 accessibleAWTComponentHandler = new AccessibleAWTComponentHandler();
             }
             if (accessibleAWTFocusHandler == null) {
+                focusHandlerSetFromComponent = true;
                 accessibleAWTFocusHandler = new AccessibleAWTFocusHandler();
             }
             if (propertyListenersCount++ == 0) {
                 Component.this.addComponentListener(accessibleAWTComponentHandler);
+                if (focusHandlerSetFromComponent) {
                 Component.this.addFocusListener(accessibleAWTFocusHandler);
             }
+            }
             super.addPropertyChangeListener(listener);
         }
 
         /**
          * Remove a PropertyChangeListener from the listener list.

@@ -9146,12 +9158,14 @@
          * @param listener  The PropertyChangeListener to be removed
          */
         public void removePropertyChangeListener(PropertyChangeListener listener) {
             if (--propertyListenersCount == 0) {
                 Component.this.removeComponentListener(accessibleAWTComponentHandler);
+                if (focusHandlerSetFromComponent) {
                 Component.this.removeFocusListener(accessibleAWTFocusHandler);
             }
+            }
             super.removePropertyChangeListener(listener);
         }
 
         // AccessibleContext methods
         //