📜  intellij java fx 新窗口 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:49.955000             🧑  作者: Mango

代码示例1
btnOpenNewWindow.setOnAction(new EventHandler() {
    public void handle(ActionEvent event) {
        Parent root;
        try {
            root = FXMLLoader.load(getClass().getClassLoader().getResource("path/to/other/view.fxml"), resources);
            Stage stage = new Stage();
            stage.setTitle("My New Stage Title");
            stage.setScene(new Scene(root, 450, 450));
            stage.show();
            // Hide this current window (if this is what you want)
            ((Node)(event.getSource())).getScene().getWindow().hide();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }
}