I'm trying to add a loading dialog that is shown while some javafx graphic are loading. The problem is that the loading of javafx graphic block the refreshing of loading dialog.
This is my code:
Stage dialogStage;
ProgressBar pb = new ProgressBar();
ProgressIndicator pin = new ProgressIndicator();
dialogStage = new Stage();
dialogStage.initStyle(StageStyle.UTILITY);
dialogStage.setResizable(false);
dialogStage.initModality(Modality.APPLICATION_MODAL);
// PROGRESS BAR
final Label label = new Label();
label.setText("alerto");
pb.setProgress(-1F);
pin.setProgress(-1F);
final HBox hb = new HBox();
hb.setSpacing(5);
hb.setAlignment(Pos.CENTER);
hb.getChildren().addAll(pb, pin);
Scene scene = new Scene(hb);
dialogStage.setScene(scene);
final Task<Void> task = new Task<Void>() {
@Override
protected Void call() throws Exception {
System.out.println(ANSI_CYAN + ANSI_RED_BACKGROUND + "START CALL" + ANSI_RESET);
for (int i = 0; i < 1; i++) {
System.out.println(ANSI_CYAN + "\tWAIT " + (i + 1) + "s;" + ANSI_RESET);
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
Logger.getLogger(FXMLDesktopController.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println(ANSI_CYAN + "\tWAITED " + (i + 1) + "s;" + ANSI_RESET);
}
Platform.runLater(() -> {
System.out.println(ANSI_CYAN + ANSI_RED_BACKGROUND + "FIRE APP" + ANSI_RESET);
startGraphic(anchorDesktop);
System.out.println(ANSI_CYAN + ANSI_RED_BACKGROUND + "APP FIRED" + ANSI_RESET);
});
for (int i = 0; i < 0; i++) {
System.out.println(ANSI_CYAN + "\tWAIT " + (i + 1) + "s;" + ANSI_RESET);
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(FXMLDesktopController.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println(ANSI_CYAN + "\tWAITED " + (i + 1) + "s;" + ANSI_RESET);
}
System.out.println(ANSI_CYAN + ANSI_RED_BACKGROUND + "END CALL" + ANSI_RESET);
return null;
}
};
pb.progressProperty().bind(task.progressProperty());
pin.progressProperty().bind(task.progressProperty());
dialogStage.show();
task.setOnSucceeded(event -> {
dialogStage.close();
System.out.println(ANSI_CYAN + ANSI_RED_BACKGROUND + "CLOSE" + ANSI_RESET);
});
Platform.runLater(() -> {
System.out.println(ANSI_CYAN + ANSI_RED_BACKGROUND + "START SHOW" + ANSI_RESET);
});
System.out.println(ANSI_CYAN + ANSI_RED_BACKGROUND + "NEW THEAD" + ANSI_RESET);
Thread thread = new Thread(task);
thread.setDaemon(true);
thread.start();
When startGraphic(anchorDesktop)
is called is block the animation of the progress bar until all the graphic is loaded.
There is a multithreading pipeline for JavaFX graphics?