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

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

问题描述

下面的代码片段给出了错误不在FX应用程序线程上; currentThread = JavaFX 应用程序线程。这个应用程序在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.

错误也不明确不在fx应用程序线程和当前线程-javafx 应用程序线程。如果当前线程是fx应用程序线程,那么它对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中没有任何问题的相同代码在那里给出了而不是fx应用程序线程错误。

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天全站免登陆