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

查看:151
本文介绍了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 。<中定义的预定义子类a href =http://docs.oracle.com/javase/7/docs/api/javax/swing/text/TextAction.html\"rel =nofollow noreferrer> javax.swing.text .TextAction 很方便,因为他们知道重点组件。另见 Q& ;一个示例的。例如,

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天全站免登陆