Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

macos - Java - How to hook into the Copy and Paste menu on the Mac OS

I understand that you can:

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

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...