我尝试在线程中更改 JavaFX GUI 节点,但看到以下错误:
线程“Thread-8”java.lang.IllegalStateException 中的异常:不在 FX 应用程序线程上;当前线程 = 线程 8
生成错误的示例代码:
public class Controller {
public Label label = new Label();
public void load() {
MyThread myThread = new MyThread();
myThread.start();
}
public class MyThread extends Thread {
public void run() {
......
label.setText(""); // IllegalStateException: Not on FX application thread
}
}
}