Javafx open another fxml in the another window with button

后端 未结 2 1524
余生分开走
余生分开走 2021-02-02 11:38

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

2条回答
  •  野性不改
    2021-02-02 12:29

    I had to modify the code a bit and it works fine. Thank you again for the code!

    public void pressButton(ActionEvent event) throws Exception {               
        try {
            FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/A.fxml"));
            Parent root1 = (Parent) fxmlLoader.load();
            Stage stage = new Stage();
            stage.setScene(new Scene(root1));  
            stage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
    

提交回复
热议问题