I need someone explain me how Preloader works in JavaFX application. I have already found out the lifecycle and I know that first is called start(..) of preloader and then start(..) of Application but is this two methods are called from the same Thread? I have tried to make a simple app in start method of application a put Thread.sleep(8000) and in the start of Preloader I created a simple stage and show it. But when I run the application it just freeze with black stage and only after 8 seconds shows preloader stage correctly, but why?
Update my post with source code:
public class PreloaderApp extends Preloader {
public void init(){
System.out.println("Thread Preloader ID:"+ Thread.currentThread().getId());
System.out.println(" ------ ");
Pane effectRegion = LoaderFrame.getInstance().getEffectPane();
JFXFillTransition fill = new JFXFillTransition();
fill.setDuration(Duration.millis(400));
fill.setRegion(effectRegion);
fill.setAutoReverse(true);
fill.setCycleCount(Animation.INDEFINITE);
fill.setFromValue(Color.WHITE);
fill.setToValue(Color.rgb(0,77,147));
fill.play();
}
@Override
public void start(Stage primaryStage){
System.out.println("Thread Preloader(start) ID:"+ Thread.currentThread().getId());
System.out.println(" ------ ");
LoaderFrame.getInstance().show();
}
}
public class LoaderFrame extends Stage {
private static final LoaderFrame instance = new LoaderFrame();
public static LoaderFrame getInstance(){
return instance;
}
private Scene scene;
private AnchorPane root;
private BorderPane wraper;
private StackPane effectPane;
private JFXButton loaderPathButton;
public LoaderFrame(){
initScene();
this.initStyle(StageStyle.TRANSPARENT);
this.getIcons().add(new Image("file:imgs/favico/icon48.png"));
}
public void initScene(){
FXMLLoader loader = new FXMLLoader(Main.class.getResource("xml/loader_frame.fxml"));
root = null;
try {
root = loader.load();
wraper = (BorderPane) root.lookup("#rootPane");
loaderPathButton = (JFXButton) root.lookup("#loaderPathButton");
effectPane = (StackPane) root.lookup("#effectPane");
scene = new Scene(root);
scene.setFill(Color.TRANSPARENT);
scene.getStylesheets().add("file:css/loader.css");
this.setScene(scene);
} catch (IOException e) {
e.printStackTrace();
}
}
public Pane getEffectPane(){
return effectPane;
}
}