我需要通过按alt + f4禁用关闭我的应用程序(在全屏模式下可用)。我阅读了其他线程并编写了以下代码:
override fun start(stage: Stage) {
Platform.setImplicitExit(false)
stage.addEventFilter(KeyEvent.KEY_PRESSED) {
if (it.isAltDown && it.code == KeyCode.F4) {
it.consume()
}
}
stage.setOnHiding { _ -> EventHandler<WindowEvent> { it.consume() } }
stage.setOnCloseRequest { _ -> EventHandler<WindowEvent> {
it.consume()
} }
stage.fullScreenExitKeyCombination = KeyCombination.NO_MATCH
stage.fullScreenExitHint = ""
stage.isFullScreen = true
super.start(stage)
}
问题是我的应用程序没有关闭,但是舞台被隐藏了。如何通过按alf + f4禁用隐藏表单?
答案 0 :(得分:1)
我尝试将onCloseRequest
设置为窗口,而不是舞台。在OS X上,我按下cmd
+ q
后,窗口最小化,但没有关闭。我想我能得到的最好的解决方案是:
//Method in my view
override fun onDock() {
super.onDock()
currentWindow?.setOnCloseRequest {
it.consume()
currentStage?.isFullScreen = true //Set the window to fullscreen again
}
}
正如我所说,此行为是在OS X上出现的,我猜这在各种OS上都会有所不同...