首页 > 解决方案 > 弹出时在顶部打开另一个 fxml

问题描述

我目前使用此代码更改 JFX 程序中的场景:

public void addTaskFunction (ActionEvent event) throws IOException{
        Parent addTaskParent = FXMLLoader.load(getClass().getResource("/LogIn/AddDataToTaskManager.fxml"));
        Scene addTaskScene = new Scene(addTaskParent);
        Stage appStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
        appStage.setScene(addTaskScene);
        appStage.setResizable(true);
        appStage.show();
    }

使用此代码关闭前一阶段并在顶部打开一个新阶段。我怎样才能使它上一个阶段不会关闭并且这个AddDataToTaskMaager.fxml在TaskManager.fxml之上打开

谢谢

标签: javajavafxjava-8

解决方案


我用@kai 的提示更改了代码

public void addTaskFunction (ActionEvent event) throws IOException{
        Parent addTaskParent = FXMLLoader.load(getClass().getResource("/LogIn/AddDataToTaskManager.fxml"));
        Scene addTaskScene = new Scene(addTaskParent);
        Stage stage = new Stage();
        stage.setTitle("Thank You");
        stage.setScene(addTaskScene);
        stage.show();
    }

推荐阅读