Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
795 views
in Technique[技术] by (71.8m points)

multithreading - How to avoid Not on FX application thread; currentThread = JavaFX Application Thread error?

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.

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);
}
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Calling

Platform.runLater(new Runnable(){
// do your GUI stuff here
});

will fix it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...