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

JComponent.getAncestorListeners() always empty

XMLWordPrintable

    • beta2
    • sparc
    • solaris_7



      Name: sdR10048 Date: 04/13/2001


      public AncestorListener[] javax.swing.JComponent.getAncestorListeners()
      returns empty array of AncestorListeners if some has been added
      previously.

      Javadoc says:
      public AncestorListener[] getAncestorListeners()

          Returns an array of all the ancestor listeners registered on this component.
          Returns:
              all of the component's AncestorListeners or an empty array if no ancestor listeners are currently registered
          Since:
              1.4
          See Also:
              addAncestorListener(javax.swing.event.AncestorListener),
              removeAncestorListener(javax.swing.event.AncestorListener)
              
      See example:
      --------------------------------------------------
      [sword] ~/tmp
      % cat test.java
      import javax.swing.*;
      import javax.swing.event.*;

      class FakeAncestorAdapter implements AncestorListener {
           public void ancestorAdded(AncestorEvent event){}
           public void ancestorRemoved(AncestorEvent event){}
           public void ancestorMoved(AncestorEvent event){}
           public boolean isChanged() {
               return false;
           }
      }

      public class test {
          public static void main(String[] args) {
              JComponent j = new JLabel();
              j.addAncestorListener(new FakeAncestorAdapter());
              AncestorListener[] ls = j.getAncestorListeners();
              System.out.println(ls.length);
          }
      }

      [sword] ~/tmp
      % java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b60)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b60, mixed mode)

      [sword] ~/tmp
      % javac test.java

      [sword] ~/tmp
      % java test
      0
      --------------------------------------------------
      ======================================================================

            peterz Peter Zhelezniakov
            dsvsunw Dsv Dsv (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: