How to use Command-c/Command-v shortcut in Mac to copy/paste text?(如何在 Mac 中使用 Command-c/Command-v 快捷方式复制/粘贴文本?)
问题描述
我有一个想要在 Mac OS X 上运行的 Java Swing 应用程序.我想使用普通的 Mac 复制/粘贴快捷方式将文本复制/粘贴到我的 Java 应用程序的文本字段中.
I have a Java Swing application that i want to run on Mac OS X. I want to use the normal Mac copy/paste shortcuts to copy/paste text to a text field in my Java application.
Ctrl+c &Ctrl+v 可以解决问题,但我想使用 Command+c &Command+v 代替.我该怎么做?
Ctrl+c & Ctrl+v does the trick but i want to use Command+c & Command+v instead. How can i do that?
推荐答案
如果您使用的是 3rd-party L&F 实现,它可能不支持 Mac 的本机键盘快捷键.以下代码应在设置 L&F 后恢复 Mac 的 JTextFields 键盘快捷键:
If you're using a 3rd-party L&F implementation it probably doesn't support the Mac's native keyboard shortcuts. The following code should reinstate the Mac's keyboard shortcuts for JTextFields after setting the L&F:
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);
当然,如果您检测到应用程序正在 Mac 上运行,您只需要这样做,这样您就不会影响其他操作系统的键盘映射.
Of course you'll only need to do this if you detect that the application is running on a Mac so that you don't affect the keyboard mappings for other OS's.
这篇关于如何在 Mac 中使用 Command-c/Command-v 快捷方式复制/粘贴文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Mac 中使用 Command-c/Command-v 快捷方式复制/粘贴文本?
基础教程推荐
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- JPA惰性列表上的流 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- 将 Windows 证书导入 Java 2022-01-01
