Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4257538

JComponent: getListeners() returning incorrect values for listeners.

XMLWordPrintable

    • sparc
    • solaris_2.5, solaris_2.6

      The implementation of getListeners() for JComponent is broken for the following listeners:

      PropertyChangeListener, AncestorListener, VetoableChangeListener

      For the following test program, getListeners() will always return 0 no matter how many listeners you add to the component.

      ----------------------------------- Cut Here ----------------------------------

      import java.beans.*;
      import java.util.*;
      import javax.swing.*;
      import javax.swing.event.*;

      public class TestGetListenersForJComponent
      implements PropertyChangeListener, AncestorListener, VetoableChangeListener {

          JToolTip aComp = new JToolTip();
          EventListener[] eventListener;

          public TestGetListenersForJComponent() {
              eventListener = aComp.getListeners(PropertyChangeListener.class);
              System.out.println("PropertyChangeListener before adding a listener: " + eventListener.length);
              eventListener = aComp.getListeners(AncestorListener.class);
              System.out.println("AncestorListener before adding a listener: " + eventListener.length);
              eventListener = aComp.getListeners(VetoableChangeListener.class);
              System.out.println("VetoableChangeListener before adding a listener: " + eventListener.length);

              aComp.addPropertyChangeListener(this);
              aComp.addAncestorListener(this);
              aComp.addVetoableChangeListener(this);

              System.out.println("");

              eventListener = aComp.getListeners(PropertyChangeListener.class);
              System.out.println("PropertyChangeListener after adding a listener: " + eventListener.length);
              eventListener = aComp.getListeners(AncestorListener.class);
              System.out.println("AncestorListener after adding a listener: " + eventListener.length);
              eventListener = aComp.getListeners(VetoableChangeListener.class);
              System.out.println("VetoableChangeListener after adding a listener: " + eventListener.length);

          }

          public void propertyChange(PropertyChangeEvent e) {}

          public void ancestorAdded(AncestorEvent e) {}

          public void ancestorMoved(AncestorEvent event) {}

          public void ancestorRemoved(AncestorEvent event) {}

          public void vetoableChange(PropertyChangeEvent evt) {}

          public static void main(String[] args) {
              new TestGetListenersForJComponent();
          }
      }

      ----------------------------------- Cut Here -----------------------------------


      edmund.lou@eng 1999-07-27
      JFC SQE

            bchristi Brent Christian
            elousunw Edmund Lou (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: