2

I'm writing an JavaFx-Application and want to force the fullscreen. I tried

mainView.getLayout().setOnKeyPressed(event -> {
        if(event.getCode() == KeyCode.ESCAPE){
        mainView.getStage().setFullScreen(true);
        }
    });

mainView.getLayout() returns a StackPane

but that's not a clean solution, when it leaves the fullscreen it automatically switches back to fullscreen. But I want to Catch the LeaveFullScreen and do nothing instead of leave and switch back.

Dylan Meeus
  • 5,696
  • 2
  • 30
  • 49
Felix Roth
  • 21
  • 1
  • A key Combination exists to force fullscreen not exist.Write stagename.estExitFullScreenKeyCombination(KeyCombination.none) something like that.Easy to find – GOXR3PLUS Jul 06 '16 at 11:06
  • 1
    Thanks, i tried "stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);" But the Escape-Key still works, how can i disable it? – Felix Roth Jul 06 '16 at 11:13
  • It must be .NONE i think.I am not in computer to check sry.Also set setFullScreenExitMessage () to null .Search this method it bhas a name like this – GOXR3PLUS Jul 06 '16 at 11:15
  • 1
    stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH); shall do the job. If it is not working, you are not calling it on the correct `Stage`. – DVarga Jul 06 '16 at 11:18
  • okay, i got it, i have to set setFullscreen(true) after setFullScreenExitKey not before. Thanks Mate! – Felix Roth Jul 06 '16 at 11:24
  • 1
    Yes, I just wanted to comment this:) From the doc of `setFullScreenExitKeyCombination` : "An internal copy of this value is made when entering FullScreen mode". – DVarga Jul 06 '16 at 11:25

2 Answers2

1

The fullScreenExitKey property of the Stage can be set to KeyCombination.NO_MATCH. This prevents any combination of keys from exiting full screen mode.

stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
stage.setFullScreen(true);
fabian
  • 80,457
  • 12
  • 86
  • 114
0

You can add a ChangeListener to the Stage full screen property:

primaryStage.fullScreenProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> observable,
                Boolean oldValue, Boolean newValue) {
            if(newValue != null && !newValue.booleanValue())
                primaryStage.setFullScreen(true);
        }
    });

For more have a look at this question here

Community
  • 1
  • 1
GOXR3PLUS
  • 6,877
  • 9
  • 44
  • 93