繁体   English   中英

如何在Java-fx中创建一个新舞台,以及如何使该舞台成为弹出窗口?

[英]How to make a new Stage in Java-fx and how to make that stage as pop-up?

我想在JavaFX中建立一个新阶段,当我单击一个按钮时,新阶段将弹出一个新scene

当新scene弹出时,将出现上一个阶段,但将不起作用。 当我关闭弹出窗口时,上一个窗口将起作用。 请帮我做到这一点。

您可以尝试使用以下代码片段:

public void start(Stage primaryStage) {
    try {
        Pane root = new Pane();
        Scene scene = new Scene(root, 400, 400);
        Button btn = new Button(); // create a btn
        root.getChildren().add(btn); // add this btn to the root

        btn.setOnAction(new EventHandler<ActionEvent>() // when click
        {
            @Override
            public void handle(ActionEvent e) {
                Stage dialog = new Stage(); // new stage
                dialog.initModality(Modality.APPLICATION_MODAL);
                // Defines a modal window that blocks events from being
                // delivered to any other application window.
                dialog.initOwner(primaryStage);
                VBox vb = new VBox(20);
                Scene dialogScene = new Scene(vb, 300, 200);
                dialog.setScene(dialogScene);
                dialog.show();
            }
        });
        primaryStage.setScene(scene);
        primaryStage.show();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM