Triggering an Event by KeyCombination in javaFX

情到浓时终转凉″ 提交于 2019-12-05 20:34:23
James_D

The default value for all the modifiers in the KeyCodeCombination constructor is RELEASED. So your save shortcut matches the key S with Shift released, Alt released, Meta released, and Control either pressed or released (the ANY value that you specified matches either pressed or released).

If you want this to only match Ctrl+S you should use

public static final KeyCombination saveShortcut = new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN);

Better still is

public static final KeyCombination saveShortcut = new KeyCodeCombination(KeyCode.S, KeyCombination.SHORTCUT_DOWN);

which would match the shortcut key appropriate to the platform (e.g. Ctrl+S on windows and Cmd+S on Mac).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!