JavaFX Full Screen Exclusive Mode

筅森魡賤 提交于 2019-12-05 17:14:23

Handle close events.

following code may help!

// Set plat params Platform.setImplicitExit(false);

primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
    @Override
    public void handle(WindowEvent event) {
// deque it
        event.consume();
    }
});

I had this same issue recently, hopefully you figured it out (I wouldn't wait 4 years for an answer).

If not:

Before you make a call to stage.show() you need to call setFullScreenExitKeyCombination and pass KeyCombination.NO_MATCH as the only parameter.

so for example...

stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
stage.show()

This will prevent closing and de-fullscreening w/ESC (but still leave you with a backdoor-y way to remove fullscreen - Shift+PAUSE or F13):

scene.setOnKeyPressed((event) ->
{
  if (event.getCode() == KeyCode.PAUSE && event.isShiftDown())
    stage.setFullScreen(!stage.isFullScreen());
});
stage.setOnCloseRequest(Event::consume);
stage.setFullScreenExitKeyCombination(new KeyCodeCombination(KeyCode.F13));

In order to close your application you'd have to add a Platform.exit() on some command.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!