2
votes

I want a javafx.stage.Stage to be in fullscreen mode on macOS with no (native) menu bar visible. Also I want that the dock is not available while the application is in fullscreen mode.

I have a Stage and I set stage.setFullScreen(true). If the style of my stage is set to stage.initStyle(StageStyle.UNDECORATED), the application displays the native menu bar and the dock. Therefore the whole screen isn't available for the application.

enter image description here

If I set the style to stage.initStyle(StageStyle.UTILITY) the menu bar is not visible, but instead there is a grey area.

enter image description here

And if I move the cursor where usually the menu bar is placed, the menu bar will show itself additionally with a small closing button and a small bar.

enter image description here

Also If I cursor the mouse down where the dock is placed, the dock will show up itself.

How can I achieve a real fullscreen application with no menubar and no dock displayed and no grey bar at the top so my application can use all of the screen size?

Code

import javafx.application.Application;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class Fullscreen extends Application {

    @Override public void start(Stage stage) throws Exception {
        AnchorPane pane = new AnchorPane();
        Scene scene = new Scene(pane);

        pane.setStyle("-fx-background-color: blue");

        stage.initStyle(StageStyle.UTILITY);
        stage.setFullScreen(true);
        stage.setScene(scene);
        stage.show();

        //stage.setHeight(stage.getHeight() + 16);
        //stage.setY(-16);
    }
}

Annotation

If I set stage.setHeight(stage.getHeight() + 16) and stage.setY(-16) after stage.show() and the style is set to stage.initStyle(StageStyle.UTILITY), the grey bar isn't visible anymore. But this seems not to be a good solution for me because it depends on the screen size (in my case 2560x1440) and I don't know how to exactly get the size of the grey bar. Also the menubar and the dock are available.

1

1 Answers

2
votes

Using Stage#setFullScreen(boolean) is the correct way. When I run this MWE, I get the expected OS X full screen (no dock, automatically hidden menu bar):

public class FullScreenDemo extends Application {

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

    @Override
    public void start(final Stage primaryStage) {
        primaryStage.setFullScreen(true);
        primaryStage.setScene(new Scene(new Label("Foo")));
        primaryStage.show();
    }

}

I don't think you can get rid of the native menu bar that pops up when you hover over its position—that's just how the OS behaves. The corresponding Javadoc also states:

The implementation of full-screen mode is platform and profile-dependent.