除了手动解析之外,Java
是否有任何默认方式将KeyStroke
翻译为可读String
?
KeyStroke ke = KeyStroke.getKeyStroke("ctrl released 1");
System.out.println(ke.toString())
Print result:
ctrl released 1
Expected:
Ctrl+1
答案 0 :(得分:2)
来自Java Swing API
:
KeyStroke accelerator = b.getAccelerator();
String acceleratorText = "";
if (accelerator != null) {
int modifiers = accelerator.getModifiers();
if (modifiers > 0) {
acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
acceleratorText += "+";
}
acceleratorText += KeyEvent.getKeyText(accelerator.getKeyCode());
}
@mKorbel,你错了,毫无根据的说它不是默认的一部分