我试图使FXML标签在特定的时间间隔内自动刷新,
但是我在下面显示了一个例外。
我在这里的尝试:
public static void showActualViewer(MixerChannel mixerChannel, Label label){
Platform.runLater(new Runnable() {
@Override
public void run() {
Timer timer = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
label.setText("Actual Viewers : " + mixerChannel.viewersCurrent);
System.out.println("works");
}
});
timer.start();
}
});
}
错误:
线程“ AWT-EventQueue-0”中的异常java.lang.IllegalStateException:在FX应用程序线程上不存在; currentThread = AWT-EventQueue-0
最佳答案
您正在使用Platform.runLater()在java fx线程中设置事件处理程序;但是,actionPerformed()方法中的代码将在事件线程上运行。要解决此问题,请在Platform.runLater()中包围actionPerformed()中的代码
希望有帮助!
关于java - 如何在内部使用Javafx和Javafx执行Timer类的对象更改,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57381550/