如何使用Mac中的Command-c / Command-v快捷方式复制/粘贴文本? [英] How to use Command-c/Command-v shortcut in Mac to copy/paste text?

查看:677
本文介绍了如何使用Mac中的Command-c / Command-v快捷方式复制/粘贴文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java Swing应用程序,我想在Mac OS X上运行。我想使用正常的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?

推荐答案

如果您使用第三方L& F实现,可能不支持Mac的本机键盘快捷键。以下代码应在设置L& F之后恢复 JTextField 的Mac键盘快捷键:

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快捷方式复制/粘贴文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆