Began to remake your project from Swing to JavaFX and faced with such a task. With me (in Swing), JFrame first opened (read: window), then, after 3 seconds, the window automatically closed and another window opened instead of it. It's simple! But in JavaFX, I can't do that! Who will help?

  • is it splash screen? - Mikhail Vaysman
  • Perhaps javafx.application.Preloader is what you need. - Ruslan P.
  • @Mikhail Vaysman Yes, this is splash screen! Thanks for the tip, I will move in this direction. - Jürgen von Markoff

2 answers 2

Try this. From minuses: the main stream is blocked.

@Override public void start(Stage primaryStage) throws Exception { Parent root = new Button("Button"); primaryStage.setScene(new Scene(root)); primaryStage.setOnCloseRequest(e -> { try { Thread.sleep(3000L); } catch (InterruptedException e1) { e1.printStackTrace(); } }); primaryStage.show(); } 

    It can be seen most have to answer your question. From the options offered, I realized that my requirements were met by a splash screen (thanks: Mikhail Vaysman). In the vastness of i-net, there were many options for splash screens, but they all seemed to be cumbersome to me. For a simple task, like mine is too much! Therefore, having processed several variants of the code, threw away all unnecessary and left only the most ... the most ... Here. Maybe someone will fit?

     public class Main extends Application { public static void main(String[] args) throws Exception { launch(args); } // этот метод запускает первое окно на n-секунд @Override public void start(final Stage stage) throws Exception { try { // Запускаем заставку Parent root = FXMLLoader.load(getClass().getResource("/fxml/splash.fxml")); stage.setScene(new Scene(root)); stage.initStyle(StageStyle.TRANSPARENT); // без обрамления stage.show(); PauseTransition delay = new PauseTransition(Duration.seconds(3)); // заставка запустится на 3 секунды delay.setOnFinished(event -> { stage.close(); // закроем окно showMainStage(); // откроем другое окно }); delay.play(); } catch (IOException exception) { throw new RuntimeException(exception); } } // этот метод запускает основное окно private void showMainStage() { try { Parent root = FXMLLoader.load(getClass().getResource("/fxml/mainWindow.fxml")); Stage stage = new Stage(); stage.setScene(new Scene(root)); stage.show(); } catch (IOException e) { e.printStackTrace(); } } }