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);
}
This happened with me when i was modifying UI element from task in javafx 2 like listview elements.A Task Which Modifies The Scene Graph helped me to solve the issue i.e. updating UI elements by
Calling
will fix it, too.
It should happens when you try to change some component UI, like a label text. Running like that works always:
You can change of Form or go to another view or fxml with this in any part of your code :
My Example in my Controller :
It's not shown explicitly in the code above, but what I'm fairly sure is happening is that somewhere you are creating a thread outside of the application (main) javafx thread, and then you are trying to preform operations on javafx objects (like closing, opening windows, etc.) on the SECOND thread. This is strictly not allowed, as only the main thread can control javafx objects directly. If this becomes a requirement of your program that you need to use the second thread for other things like computations, etc, etc. You must use some form of message passing to let the other thread know that you want to do whatever javafx action.
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.