如何避免不在 FX 应用线程上;currentThread = JavaFX 应用程序线程错误? [英] How to avoid Not on FX application thread; currentThread = JavaFX Application Thread error?

查看:49
本文介绍了如何避免不在 FX 应用线程上;currentThread = JavaFX 应用程序线程错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码片段给了我错误 不在 FX 应用程序线程上;currentThread=JavaFX Application Thread.这个应用程序在 java 1.7 中运行良好,但是当我将它移到 fx8 时,它现在给出错误.当我第一次尝试启动应用程序时,它按预期工作.但是在关闭舞台并再次打开它后,它不起作用.

Below code snippets is giving me error Not on FX application thread; currentThread=JavaFX Application Thread.This application was working fine in java 1.7 but when i moved it to fx8 it is now giving error. when I start the application on my 1st attempt it is working as intended .But after closing the stage and opening it again it is not working.

错误也有歧义Not On fx application thread and current thread-javafx application thread.如果当前线程是,not on fx application thread是什么意思一个 fx 应用程序线程.

The error is also ambiguous Not On fx application thread and current thread- javafx application thread.What did it mean by not on fx application thread if the current thread is a 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);
}

推荐答案

Platform.setImplicitExit(false); 解决了我的问题.我认为他们更改了 JavaFX 8 中的实现,因此在 JavaFX 2 中没有任何问题的相同代码在那里给出了 not an fx application thread 错误.

Platform.setImplicitExit(false); solved my problem. I think they changed the implementation in JavaFX 8, so the same code that works without any issue in JavaFX 2 gives the not an fx application thread error there.

这篇关于如何避免不在 FX 应用线程上;currentThread = JavaFX 应用程序线程错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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