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

后端 未结 1 372
北恋
北恋 2020-11-27 23:44

I understand that you can:

// Where CustomMacOSXController implements implements MRJAboutHandler, ...
CustomMacOSXController macOSXController = new CustomMac         


        
相关标签:
1条回答
  • 2020-11-28 00:33

    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.

    0 讨论(0)
提交回复
热议问题