简体   繁体   English

在秋千上不被称为财产变化

[英]in swing worker propertychange isn't being called

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. 我已经将挥杆工设置为内部类,并在字符串propyName = evt .....上放置了一个断点,但它从未达到断点。

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();
}

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. 您可以看到,当任务完成时,我将对象work2设置为null,现在不再将其设置为null。 In the class I added a done routine which it hits when the doinbackground is finished. 在课堂上,我添加了一个完成的例程,该例程会在doinbackground完成时触发。 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++;
    }
}

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. 我看了看文档,没有看到必须手动触发某种属性更改,所以我真的非常受困,并希望另一双眼睛告诉我我犯了什么愚蠢的错误。

Thanks, Ilan 谢谢,伊兰

It turned out my Java was corrupted. 原来我的Java损坏了。 Removing JDK 1.6 and reinstalling it from the repository wasn't good enough. 删除JDK 1.6并从存储库中重新安装它还不够好。

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中到1.6的链接遭到损坏,我也不得不重新安装Netbeans(在此过程中转到7.3.1)。 Netbeans would not recognize the repository JDK 1.6 as valid so I had to go to Oracle and get the original version. Netbeans无法识别存储库JDK 1.6是有效的,因此我不得不转到Oracle并获得原始版本。 Netbeans recognized the original and the problem I reported above was no longer a problem. Netbeans识别出原始文件,而我在上面报告的问题不再是问题。

I removed the void done() routine since it had no purpose other than a place to put a break point. 我删除了void done()例程,因为它除了放置断点以外没有其他用途。 The code as such is OK. 这样的代码就可以了。 Thanks for the help. 谢谢您的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM