1

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.

Stephane Grenier
  • 15,527
  • 38
  • 117
  • 192

1 Answers1

4

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I'm sorry but I don't really understand what you're saying. In this case you're attaching an Action to a new JMenuItem and JButton, but it doesn't link it up to the Copy and Paste menu in an Apple application... – Stephane Grenier Apr 15 '12 at 15:52
  • 2
    See also this [answer](http://stackoverflow.com/a/8956715/230513) about moving Java menus to the Mac menu bar and this [anwser](http://stackoverflow.com/a/10161155/230513) about menu accelerators. – trashgod Apr 15 '12 at 16:39
  • Seems like you had one magic box at home, from which you bring these wonderful examples here and there :-) , send me one if you can :-) – nIcE cOw Jun 24 '12 at 17:41
  • 1
    @nIcEcOw: This [example](https://sites.google.com/site/drjohnbmatthews/keypad-panel) shows how to _forward_ one `Action` to another. – trashgod Jun 24 '12 at 17:48
  • Ahha, this one is amazing, never used `Action` like this, one event can trigger someone else's event. That's wonderful :-) – nIcE cOw Jun 24 '12 at 17:54