按下ESC退出全屏模式后,如何在javafx中返回全屏?

我要使功能在按ESC退出全屏模式后返回全屏模式.

有什么方法可以返回全屏显示吗?

例如,
要执行全屏模式,我使用了以下方法

@Override
public void init(Controller controller) {
    sound.backgroundMusic();
    menuButtons = new ArrayList<>();
    createSubScenes(controller);
    createButtons(controller);
    createBackground();
    createLogo();
    controller.setScene(mainScene);

}

public void setScene(Scene scene) {
    Platform.runLater(() -> stage.setScene(scene));
    Platform.runLater(() -> stage.setFullScreen(true));
}

在舞台上,当我按ESC时,舞台退出到全屏.
enter image description here

enter image description here

然后在这个阶段,我希望能够返回到全屏模式.

解决方法:

防止通过ESC(或其他任何键)使用全屏模式:

stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);

如果您不处于全屏模式,请创建一个侦听器或方法以全屏执行:

stage.setFullScreen(true);
上一篇:JavaFX 11:“缺少JavaFX运行时组件”


下一篇:JavaFX源码分析和实战之音频播放:MediaPlayer和AudioClip播放音频剪辑以及AudioClip与MediaPlayer的区别