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.
If I set the style to stage.initStyle(StageStyle.UTILITY) the menu bar is not visible, but instead there is a grey area.
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.
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.



                        
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):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: