1

I use this to setFullScreen():

scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
        @Override
        public void handle(KeyEvent e) {
            if(e.getCode() == KeyCode.F11) {
                stage.setFullScreen(true);
            }
        }
    });

And this line to exit it:

stage.setFullScreenExitKeyCombination(new KeyCodeCombination(KeyCode.F11));

And as you can see, I want to use the same KeyCode (F11) for both. But it doesn't exit the fullScreen correctly! I guess, it's setting the fulscreen just after it exited it. So it doesn't close the fullScreenMode.

  • What happens if you disable the fullscreening portion until it's windowed? If it happens right after, you may need to enable it after a short timeout – phflack Jan 30 '18 at 19:36
  • Isn't there an easier way or is that the only? –  Jan 30 '18 at 19:39
  • If what you theorize is true (it's fullscreening right after becoming windowed), checking if it's windowed won't be enough. Easiest way is to test it, ie `if(e.getCode() == KeyCode.F11 && isWindowed())` – phflack Jan 30 '18 at 19:42

2 Answers2

2

This is the easiest answer to your question.

scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent e) {
    if(e.getCode() == KeyCode.F11) {
        stage.setFullScreen(!stage.isFullScreen());
    }
}
});
nitishk72
  • 1,616
  • 3
  • 12
  • 21
0

Just set a flag that fullscreen is true/false and that it.

boolean fullScreen = false;            // This is global variable.
scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
    @Override
    public void handle(KeyEvent e) {
        if(e.getCode() == KeyCode.F11) {
            if(fullScreen)
               stage.setFullScreen(true);
             else
               stage.setFullScreen(false);
            // Toggling fullscreen variable after toggling full screen
            fullScreen = !fullScreen;
        }
    }
});
nitishk72
  • 1,616
  • 3
  • 12
  • 21
  • While probably the simplest, it may not be very robust. There may be ways for the boolean to become out of sync, but worst case scenario is you have to press F11 twice before it corrects itself – phflack Jan 30 '18 at 19:44
  • Thanks! I'm not shure, what a flag is in this case, but I've just added `!stage.isFullScreen()` instead! –  Jan 30 '18 at 19:52
  • Now I updated the code and Now I am updating the variable after Toggling the fullScreen – nitishk72 Jan 30 '18 at 19:53