我想在JavaFX中创建一个新阶段,当我点击一个按钮时,新阶段会弹出一个新的scene
。
当新的scene
弹出前一阶段时会出现,但不起作用。当我关闭弹出窗口时,前一个窗口将起作用。请帮帮我。
答案 0 :(得分:0)
您可以尝试使用以下代码段:
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();
}
}