Felix Roth
Felix Roth

Reputation: 21

Catch LeaveFullscreen in JavaFx

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.

Upvotes: 2

Views: 362

Answers (2)

fabian
fabian

Reputation: 82461

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

Upvotes: 1

GOXR3PLUS
GOXR3PLUS

Reputation: 7255

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

Upvotes: 0

Related Questions