Javafx open another fxml in the another window with button

Sevi picture Sevi · Nov 27, 2014 · Viewed 66k times · Source

Is it possible in javafx to open new stages (windows) from another fxml with a button? Thanks for the answers.

Answer

SimplyMe picture SimplyMe · Nov 27, 2014

Use the code below on button click:

try {
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("Demo.fxml"));
    Parent root1 = (Parent) fxmlLoader.load();
    Stage stage = new Stage();
    stage.initModality(Modality.APPLICATION_MODAL);
    stage.initStyle(StageStyle.UNDECORATED);
    stage.setTitle("ABC");
    stage.setScene(new Scene(root1));  
    stage.show();
}