Updating your UI and forcibly waiting before continuing JavaFX

后端 未结 2 838
攒了一身酷
攒了一身酷 2020-11-29 13:20

I show here an image of my welcome scene.

The current behavior of the Create New Project button is shown here:

Stage stage = (Stage)(         


        
2条回答
  •  我在风中等你
    2020-11-29 13:43

    You should try adding in ControlsFX this will help.

    You can do the following:

       Service service = new Service(){
           @Override
           protected Task createTask() {
           return new Task() {
              @Override
              protected T call() throws Exception {
            //Do your processing here.                      }
              };
          }
        };
        service.setOnSucceeded(event -> {//do your processing});
        service.setOnFailed(event -> {//do your processing});              
        ProgressDialog pd = new ProgressDialog(service);
        pd.setContentText("Please wait while the window loads...");
        pd.initModality(Modality.WINDOW_MODAL);
        pd.initOwner(stage);
        service.start();
    

    This will put your code on the background thread. ControlsFX dialogs start and stop with the service.

提交回复
热议问题