我如何在javafx的一个窗口中打开不同的阶段?

时间:2018-09-08 10:41:35

标签: javafx javafx-8 javafx-2

尊敬的开发人员,我有更多的阶段,但是当我打开任何阶段时,如下面的图片所示,因此,亲爱的开发人员,我需要在一个窗口中了解如何编写代码吗?


enter image description here

此代码例如开放舞台

@FXML
    public void btnsaveinvoice() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("/FX/saveinvoice.fxml"));
        Scene scene = new Scene(root);
        Stage stage = new Stage();
        stage.initStyle(StageStyle.UNDECORATED);
        stage.setScene(scene);
        stage.setTitle("saveInvoice");
        stage.getIcons().add(new Image(getClass().getResourceAsStream("/image/restlogo.png")));
        stage.show();

    }

这是用于销​​售发票公开阶段的

@FXML
    public void opensalesinvoice() {
        try {
            FXMLLoader fxmlLoader = new FXMLLoader();
            fxmlLoader.setLocation(getClass().getResource("/FX/salesinterface.fxml"));
            Scene scene = new Scene(fxmlLoader.load());
            Stage stage = new Stage();
            stage.getIcons().add(new Image(getClass().getResourceAsStream("/image/restlogo.png")));
            stage.setTitle("SalesInvoice");
            stage.setScene(scene);

            stage.show();
        } catch (IOException e) {
            Logger logger = Logger.getLogger(getClass().getName());
            logger.log(Level.SEVERE, "Failed to create new Window.", e);
        }
    }

1 个答案:

答案 0 :(得分:-1)

您需要像这样将子阶段设置为父阶段

childStage.initOwner(parentStage);

EX。

@FXML
public void btnsaveinvoice() throws IOException {
    Parent root = FXMLLoader.load(getClass().getResource("/FX/saveinvoice.fxml"));
    Scene scene = new Scene(root);
    Stage stage = new Stage();
    stage.initStyle(StageStyle.UNDECORATED);
    stage.setScene(scene);
    stage.setTitle("saveInvoice");
    stage.iniOwner(primaryStage); // or whatever your primaryStage is
    stage.getIcons().add(new Image(getClass().getResourceAsStream("/image/restlogo.png")));
    stage.show();

}