Java - 如何连接到 Mac OS 上的复制和粘贴菜单 [英] Java - How to hook into the Copy and Paste menu on the Mac OS

查看:25
本文介绍了Java - 如何连接到 Mac OS 上的复制和粘贴菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以:

// Where CustomMacOSXController implements implements MRJAboutHandler, ...
CustomMacOSXController macOSXController = new CustomMacOSXController()

MRJApplicationUtils.registerAboutHandler(macOSXController); 
MRJApplicationUtils.registerPrefsHandler(macOSXController);
//... and so on

但是,我找不到任何可以挂钩复制和粘贴菜单的内容,因此在调用它时,当前选定的 JTextField 会受到影响(例如,粘贴会将剪贴板粘贴到选定的 JTextField 中.

However I can't find anything to hook the copy and paste menu so that when it's called, the currently selected JTextField will be affected (for example the paste will paste the clipboard into the selected JTextField.

推荐答案

与 Mac OS X 的系统和应用程序"菜单不同,编辑"菜单完全在您的程序范围内.您必须使用适当的 Action. 中定义的预定义子类javax.swing.text.TextAction 很方便,因为它们知道焦点组件.另请参阅此相关问答示例.例如,

Unlike the Mac OS X System and Application menu, the Edit menu is entirely under the purview of your program. You have to create and populate it with the approariate Action. The pre-defined subclasses defined in javax.swing.text.TextAction are handy, as they are aware of the focused component. See also this related Q&A and example. For example,

Action pasteAction = new DefaultEditorKit.PasteAction();
JMenuItem pasteItem = new JMenuItem(pasteAction);
JButton pasteButton = new JButton(pasteAction);

附录:要将您的编辑"菜单完全集成到 Mac OS X 中,您必须告诉操作系统使用您的菜单,使用显示的方法之一 此处.要获取平台相关的修饰键,请使用 getMenuShortcutKeyMask(),如此处所示.最后,Charles Bell 的 HTMLDocumentEditor 是一个使用 文本操作的示例.

Addendum: To fully integrate your Edit menu into Mac OS X, you must tell the operating system to use your menu, using one of the approaches shown here. To obtain the platform-dependent modifier key, use getMenuShortcutKeyMask(), as shown here. Finally, Charles Bell's HTMLDocumentEditor is an example that uses the text actions.

这篇关于Java - 如何连接到 Mac OS 上的复制和粘贴菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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