1

I have a JavaFx application and I want a certain task to be trigger from the UI, but I also want it to run on a separate thread so it doesn't freeze the UI.

If this separate thread should fail, I want to create a JavaFX alert dialog to alert the user to the failure. The issue is since this task is running in another thread it cannot spawn JavaFx dialog boxes.

Here's my code where I create the other thread...

Main.altThread = new Thread(){
    public void run(){
        try{
            DO_THE_THING();
        }catch(Exception e){
            showAlert("There was an error!"); // <-- This method creates a JavaFx alert box
        }
    }
};
Main.altThread.start();

Does anyone know how I can work around this?

Ryan Stull
  • 1,056
  • 14
  • 35

0 Answers0