Universal JMenu on Mac

Discussion in 'Mac Programming' started by Abion47, Jun 3, 2010.

  1. Abion47 macrumors newbie

    Jun 3, 2010
    Looking around this forum and Google, I see a lot of examples of using:

    System.setProperty("apple.laf.useScreenMenuBar", "true");
    for setting the JMenuBar in the Mac Menu in the upper left. The only problem is that it doesn't really work in a multi-JFrame environment, since there's a different menu bar for each JFrame.

    Is there a way to make a universal menu bar that stays visible and has the same functionality over every instance of JFrame? Or do I have to basically duplicate my JMenu code over every single class that extends JFrame?
  2. mrbash macrumors 6502

    Aug 10, 2008
    If you are unconcerned with portability, then use the package com.apple.eawt as the central UI Window.

    Your other option is to create an OSX specific bundle where you can place your system properties.

    Otherwise, simply use the -Dapple.laf.useScreenMenuBar=true parameter in the command line.

    Oracle has a fine intro titled Bringing your Java Application to Mac OS X that should explain the specific changes you would make.
  3. Abion47 thread starter macrumors newbie

    Jun 3, 2010
    All this is pure gold for developing Java applications on a Mac, but I didn't see anywhere in those links about creating a universal menu bar. Maybe I'm just blind...?

    What I'm talking about is making a universal file menu, edit menu, format, tools, options, etc., not customizing the "About this program" or preferences.
  4. mrbash macrumors 6502

    Aug 10, 2008
    Your options are to write your own JFrame and subclass all other JFrames from that, or control the JMenu instance in each JFrame through a single factory.

Share This Page