【问题标题】:How to make a new Stage in Java-fx and how to make that stage as pop-up?如何在 Java-fx 中创建一个新阶段以及如何使该阶段弹出?
【发布时间】:2016-04-18 00:43:59
【问题描述】:

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

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

【问题讨论】:

标签: java javafx


【解决方案1】:

您可以尝试使用下面的代码 sn-p:

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();
    }
}

【讨论】:

    猜你喜欢
    • 2016-03-08
    • 2017-05-20
    • 1970-01-01
    • 1970-01-01
    • 2014-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多