cgu*_*ull 20
如果您使用的是第三方L&F实现,它可能不支持Mac的本机键盘快捷键.以下代码应JTextField
在设置L&F后恢复Mac的键盘快捷键:
InputMap im = (InputMap) UIManager.get("TextField.focusInputMap");
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.META_DOWN_MASK), DefaultEditorKit.copyAction);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.META_DOWN_MASK), DefaultEditorKit.pasteAction);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.META_DOWN_MASK), DefaultEditorKit.cutAction);
Run Code Online (Sandbox Code Playgroud)
当然,如果您检测到应用程序在Mac上运行,您只需执行此操作,这样就不会影响其他操作系统的键盘映射.