JavaFx 2.2&全屏模式

时间:2012-09-05 05:23:48

标签: fullscreen javafx-2

美好的一天!

我尝试了我的第一个应用程序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

1 个答案:

答案 0 :(得分:6)

你需要

dialogStage.initOwner(primaryStage);