我将此用于setFullScreen()
:
scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent e) {
if(e.getCode() == KeyCode.F11) {
stage.setFullScreen(true);
}
}
});
这一行退出它:
stage.setFullScreenExitKeyCombination(new KeyCodeCombination(KeyCode.F11));
正如您所看到的,我想对两者使用相同的KeyCode
(F11)。但它没有正确退出fullScreen!我猜,它是在它退出之后设置的全屏。所以它不会关闭fullScreenMode。
答案 0 :(得分:1)
这是您问题的最简单答案。
scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent e) {
if(e.getCode() == KeyCode.F11) {
stage.setFullScreen(!stage.isFullScreen());
}
}
});
答案 1 :(得分:0)
只需设置一个全屏为真/假的标志即可。
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;
}
}
});