【发布时间】:2014-01-31 18:22:07
【问题描述】:
下面的代码 sn-ps 给我错误Not on FX application thread; currentThread=JavaFXApplication Thread。这个应用程序在 java 1.7 中运行良好,但是当我将它移到 fx8 时它现在给出错误。当我第一次尝试启动应用程序时,它按预期工作。但是在关闭舞台并再次打开它之后,它就不起作用了。
错误也是模棱两可的Not On fx application thread and current thread- javafxapplication thread。如果当前线程是fx应用线程,那么not on fx application thread是什么意思。
progressDialog = createProgressDialog(service);
progressDialog.show();
progressDialog.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
// if (service.isRunning()) {
// service.cancel();
progressDialog.close();
// }
}
});
@SuppressWarnings("unchecked")
private Stage createProgressDialog(final Service<IStatus> service) {
stage = new Stage();
URL url = FileLocator.find(Activator.getDefault().getBundle(),
new Path("icons/xxx_16x16.png"), null); //$NON-NLS-1$
stage.getIcons().add(new Image(url.getFile()));
stage.setTitle("Downloading ..."); //$NON-NLS-1$
// Creating StackPane
stage.initModality(Modality.WINDOW_MODAL);
}
【问题讨论】:
-
您能否为您的问题添加更多代码/描述,重点关注线程?您肯定在某处(明确地或通过库)实例化一个新线程。
-
编辑您的代码,使其成为sscce,答案将显而易见。
标签: multithreading javafx javafx-8 javafx-2