Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFx 2.2 & Fullscreen mode

Good day!

I try my first application JavaFx. I set the full-screen mode and press the button shows a dialog. When the dialog appears the main window loses its full-screen.

Code:

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

OS: Windows 7

like image 307
Alexander Avatar asked Sep 05 '12 05:09

Alexander


1 Answers

You need to

dialogStage.initOwner(primaryStage);
like image 76
Uluk Biy Avatar answered Sep 17 '22 18:09

Uluk Biy