javafx在子线程中改变数据并将其设置显示在图形化控件上报错的解决方法

报错信息:

Exception in thread "Thread-" java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-

显示信息不在 FX application线程中,

原错误代码为:

...
@FXML
private Button showFile;
...
@FXML
public void onSaveFile(ActionEvent event) {
	...
        showFile.setText("文件接受完成");
        ...
}

正确的姿势

...
@FXML
private Button showFile;
...
@FXML
public void onSaveFile(ActionEvent event) {
	...
	Platform.runLater(()->{
        showFile.setText("文件接受完成");
        });
    ...
}


你可能感兴趣的:(java开发)