7

再会!

我尝试了我的第一个应用程序 JavaFx。我设置全屏模式并按下按钮显示一个对话框。当对话框出现时,主窗口将失去全屏显示。

代码:

public class Test1 extends Application {

    @Override
    public void start(final Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                Stage dialogStage = new Stage(StageStyle.UTILITY);
                dialogStage.initModality(Modality.APPLICATION_MODAL);
                dialogStage.setScene(new Scene(VBoxBuilder.create().
                    children(new Text("Hi"), new Button("Ok.")).
                    alignment(Pos.CENTER).padding(new Insets(5)).build()));
                dialogStage.show();

                System.out.println(dialogStage.getOwner()==primaryStage.getOwner());
            }
        });

        StackPane root = new StackPane();
        root.getChildren().add(btn);

        Rectangle2D r = Screen.getPrimary().getBounds();
        Scene scene = new Scene(root, r.getWidth(), r.getHeight());

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.setFullScreen(true);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

操作系统:Windows 7

4

1 回答 1

6

你需要

dialogStage.initOwner(primaryStage);
于 2012-09-05T08:04:37.960 回答