[英]Handling JavaFX event in function key
How can I add a function key (ie the F1 to F12 keys) for shortcut key in JavaFX? 如何在JavaFX中为快捷键添加功能键(即F1至F12键)? I use save button.
我使用保存按钮。 I don't need to click save button and it make easy to system
我不需要单击保存按钮,它使系统变得容易
If you are using a Button, let's say saveButton
and it is in Scene scene
then you can set accelerator(shortcut key) to button as following: 如果您使用的是按钮,假设
saveButton
处于场景scene
则可以按以下方式将加速器(快捷键)设置为按钮:
Button saveButton = new Button("save");
scene.getAccelerators().put(new KeyCodeCombination(KeyCode.F1), saveButton::fire);
KeyCodeCombination
in above code is used to set accelerators to javaFX contols and It takes, as argument, KeyCode
eg KeyCode.K
, KeyCode.F3
etc. and/or KeyCombination
like KeyCombination.SHORTCUT_DOWN
etc. 上面代码中的
KeyCodeCombination
用于将加速器设置为javaFX contols,它以KeyCode
作为参数,例如KeyCode.K
, KeyCode.F3
等和/或KeyCombination
例如KeyCombination.SHORTCUT_DOWN
等)。
and if you are using MenuItem let's say saveMenu
then you can set accelerator(shortcut key) to it as following: 如果您使用的是MenuItem,例如说
saveMenu
则可以按以下方式saveMenu
设置加速器(快捷键):
MenuItem saveMenu = new MenuItem("save");
saveMenu.setAccelerator(new KeyCodeCombination(KeyCode.F1));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.