AncestorNotifier激活事件AncestorAdded两次

时间:2017-06-12 13:01:31

标签: java swing events listener

我已将AncestorListener添加到我的组件中,发现以下问题: 每次显示组件时,都会调用ancestorAdded(AncestorEvent事件)方法两次。从方法AncestorNofifier.componentShown触发事件,并从方法AncestorNotifier.propertyChange触发一次。

addAncestorListener(new AncestorListener() {
      @Override
      public void ancestorAdded(AncestorEvent event) {
        //do sth.
      }

      @Override
      public void ancestorRemoved(AncestorEvent event) {
         //do sth.
      }

      @Override
      public void ancestorMoved(AncestorEvent event) {
        //not used
      }
    });

enter image description here

enter image description here

有谁知道如何防止这些事件之一?

感谢。

0 个答案:

没有答案