在 Swing 工人 propertychange 中没有被调用 [英] in swing worker propertychange isn't being called

查看:16
本文介绍了在 Swing 工人 propertychange 中没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用多年的代码,今天早上我注意到在任务完成时没有调用属性更改.我已将 Swing Worker 设置为内部类,并在 String 属性名称 = evt ..... 上设置了一个断点,但它从未达到断点.

I have code which I have been using for years and this morning I noticed property change isn't being called when the task is done. I've got the swing worker set up as an inner class and I put a break point on the String properyName = evt..... and it never hits the break point.

void loadData() {
    work2 = new bkgdLoadData();
    work2.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            String propertyName = evt.getPropertyName();
            if( propertyName.equals("state")) {
                SwingWorker.StateValue state = (SwingWorker.StateValue) evt.getNewValue();
                if( state == SwingWorker.StateValue.DONE) {
                    work2 = null;
                }
            }
        }
    });
    work2.execute();
}

您可以看到我在任务完成时将对象 work2 设置为 null,现在它不再设置为 null.在课堂上,我添加了一个完成的例程,当 doinbackground 完成时它会命中.令我困惑的是为什么没有触发属性更改侦听器.一定有什么东西在我没有注意到的情况下发生了变化.

You can see that I set the object work2 to null when the task is finished and now it is no longer being set to null. In the class I added a done routine which it hits when the doinbackground is finished. What is puzzling me is why the property change listener isn't triggered. Something must have changed without my noticing.

protected class bkgdLoadData extends SwingWorker<Integer, Object> {
    @Override
    protected Integer doInBackground() {
        switch(bkgdMode) {
            case 0:
                doRead();
                break;

            case 1:
                doWrite();
                break;

            case 2:
                runRobot();
                break;
        }
        return 0;
    }

    @Override
    protected void done() {
        int i=0;
        i++;
    }
}

已命中 done 处的断点,但未传递属性更改通知.(我把完成的例程放在唯一的目的是验证摇摆工人知道它已经完成.)

The breakpoint at done is hit but no property change notice is delivered. (I put the done routine for the sole purpose of verifying that the swing worker knows that it is done.)

我查看了文档,我没有看到我必须手动触发某种属性更改,所以我真的,真的被卡住了,希望有另一双眼睛告诉我我犯了什么愚蠢的错误.

I looked at the documentation and I don't see that I have to manually fire off some sort of property change, so I am really, really stuck and would appreciate another pair of eyes to tell me what stupid mistake I am mistaking.

谢谢,宜兰

推荐答案

原来我的 Java 已损坏.删除 JDK 1.6 并从存储库中重新安装它还不够好.

It turned out my Java was corrupted. Removing JDK 1.6 and reinstalling it from the repository wasn't good enough.

我在 Netbeans 中到 1.6 的链接损坏了,我也不得不重新安装 Netbeans(在此过程中转到 7.3.1).Netbeans 不会将存储库 JDK 1.6 识别为有效,因此我不得不去 Oracle 获取原始版本.Netbeans 认出了原来的,我上面报告的问题已经不是问题了.

My links in Netbeans to 1.6 got damamged and I had to reinstall Netbeans as well (going over to 7.3.1 in the process). Netbeans would not recognize the repository JDK 1.6 as valid so I had to go to Oracle and get the original version. Netbeans recognized the original and the problem I reported above was no longer a problem.

我删除了 void done() 例程,因为它除了放置断点之外没有其他用途.这样的代码是可以的.感谢您的帮助.

I removed the void done() routine since it had no purpose other than a place to put a break point. The code as such is OK. Thanks for the help.

这篇关于在 Swing 工人 propertychange 中没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆