Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JavaFx 8 installer update UI using threads problem

a76fabaa-f08c-41de-a768-552070cf4234Nov 30 2018 — edited Nov 30 2018

Hello everyone,

I'm trying to create a dynamic installer with JavaFx where it reads from a config file, reads all the information with what it should run and show to the user the options and when it runs, show the progress in each step.

My problem is when I try to run the installer, I've put inside a Task the function that iterates in each step, so I can update the UI in the most computing intensive steps, and I need to make the Task wait in specific steps for user input (a windows shows with results of the previous steps and asks the user what to do) but when it shows the window the installer continues to the next steps without waiting for the user input.

Installer window example:

installerWindow.png

Installer with second window when running:

installerPopup.png

The code is basically something like:

public void start(Stage primaryStage){

 //read config file and build mainInstaller window

 Button runInstallButton = new Button("Install");

 runInstallButton.setOnnAction(e->{

           Task\<Void> task = new Task\<Void>(){

            @Override

            protected Void call() throws SQLException{

                runInstaller();

                return null;

            }

        };

      Thread th = new Thread(task);

        th.setDaemon(true);

        th.start();

 });

}

public void showWindow(){

 //build and show window UI and wait for user input

}

public void runInstaller(){

 Object \[\]\[\] installerData;

 for(int step=0;step\<numSteps;step++)

      for int actionsInStep=0; actionsInStep\<numActions;actionsInStep++)

           switch(installerData\[step\]\[actionsInStep\].type){

           Actiontype.type1:

                //do stuff without opening window and update UI progress using Platform.runLater

           break;

           Actiontype.type2:

                //do stuff and open new window for user input

                showWindow();

                //it doesn't stop after showing the window and continues the for cycle

           break;

           }

}

Thank you

Comments
Post Details
Added on Nov 30 2018
0 comments
210 views