I am triying to create a loading window before real application window openning. There is a progressBar in the loading scene and it is undeterminate.
Problem is that; progressbar does not work until the real window open when i execute the program.
by the way i tried preloader class, but also not works too.
here is my code;
public class MainApp2 extends Application {
private Stage loadingStage = new Stage();
public static void main(String[] args) {
launch(args);
}
public void start(final Stage mainStage) throws Exception {
//loading..
loadingScreen();
//start...
appScreen();
}
private void loadingScreen() {
ProgressBar bar = new ProgressBar(ProgressIndicator.INDETERMINATE_PROGRESS);
bar.setPrefWidth(300);
bar.setPrefHeight(200);
loadingStage.initStyle(StageStyle.TRANSPARENT);
loadingStage.initStyle(StageStyle.UNDECORATED);
loadingStage.setScene(new Scene(bar));
loadingStage.show();
}
private void appScreen() {
new Task<Void>() {
@Override
protected Void call() throws Exception {
Stage mainStage = new Stage();
//get real window
Scene root = new Scene(new MyAppWindow().getAppWindow());
mainStage.setScene(root);
mainStage.centerOnScreen();
mainStage.show();
// loadingStage.close();
return null;
}
}.run();
}
public class MyAppWindow {
public BorderPane getAppWindow(){
System.out.println("may be initialize take a long time...");
for (int i = 0; i < 90000000; i++) {
System.out.print("");
}
return new BorderPane(new Label("Here is real application Window!"));
}
}
}