Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 可读击键_Java_Swing_Keystroke - Fatal编程技术网

Java 可读击键

Java 可读击键,java,swing,keystroke,Java,Swing,Keystroke,在Java中,除了手动解析之外,是否有任何默认方法将击键转换为可读的字符串 KeyStroke ke = KeyStroke.getKeyStroke("ctrl released 1"); System.out.println(ke.toString()) Print result: ctrl released 1 Expected: Ctrl+1 从JavaSwingAPI: KeyStroke accelerator = b.getAccelerator(); String acc

Java
中,除了手动解析之外,是否有任何默认方法将
击键
转换为可读的
字符串

KeyStroke ke = KeyStroke.getKeyStroke("ctrl released 1");
System.out.println(ke.toString())

Print result:
ctrl released 1

Expected:
Ctrl+1

JavaSwingAPI

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,你说它不是默认值的一部分,这是错误的,毫无根据的,除非是手动解析。你想要的格式是自定义格式,所以显然你需要手动解析或格式化。@camickr感谢mKorbel的翻译:)