计时器错误java.lang.IllegalStateException [英] Timer error java.lang.IllegalStateException

查看:164
本文介绍了计时器错误java.lang.IllegalStateException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图显示一个标签说在JRE 8中只有3秒钟是正确的,因为我不能在JRE 7中使用DatePicker,并且我会看到此错误.

I'm trying to show a label to say that all is correct only for 3 seconds in JRE 8 because I can't use DatePicker in JRE 7 and I recive this error.

    Exception in thread "Timer-2" java.lang.IllegalStateException: Not on FX application thread; currentThread = Timer-2
at com.sun.javafx.tk.Toolkit.checkFxUserThread(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(Unknown Source)
at javafx.scene.Scene.addToDirtyList(Unknown Source)
at javafx.scene.Node.addToSceneDirtyList(Unknown Source)
at javafx.scene.Node.impl_markDirty(Unknown Source)
at javafx.scene.Node$7.invalidated(Unknown Source)
at javafx.beans.property.BooleanPropertyBase.markInvalid(Unknown Source)
at javafx.beans.property.BooleanPropertyBase.set(Unknown Source)
at javafx.css.StyleableBooleanProperty.set(Unknown Source)
at javafx.scene.Node.setVisible(Unknown Source)
at Pantallas.PersonalContabilidad$1.run(PersonalContabilidad.java:221)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)

correct是一个标签,我显示3秒钟,它在correct.setVisible(false);处失败,这是第221行

correct is a label and I show that 3 seconds and it fails at correct.setVisible(false); this is line 221

    correct.setVisible(true);
    timer.schedule(new TimerTask() {
    @Override
        public void run() {
        correct.setVisible(false);
    }
    }, 3*1000);

推荐答案

正确的标签应从FX应用程序线程中更新.您应该在此处使用Platform.runLater().

The label correct should be updated from FX application thread. You should use Platform.runLater() here.

correct.setVisible(true);
timer.schedule(new TimerTask() {
@Override
    public void run() {
    Platform.runLater(new Runnable() {
       public void run() {
          correct.setVisible(false);
      }
    });
}
}, 3*1000);

这篇关于计时器错误java.lang.IllegalStateException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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