Search code examples
javamacosjava-7menubar

Mac OS X Java menu bar disappears


I'm running a Java application on Max OS X 10.7.5 and using Java 7. My application has its own menu bar. When I click one menu item it will bring a dialog. Problem is when I invoke the dialog, whole menu bar disappears and after I close the dialog menu bar appears. This problem is not seen on Java 6 and only on Java 7.

Any suggestions?


Solution

  • The menu bar you see corresponds to the current active window. Since you dialog does not have a menu bar of its own, none will show when it is the active window. Then when your dialog closes and your application window becomes active, its menu bar will again be displayed.

    One solution is to use setDefaultMenuBar(). See this example:

    Application app = Application.getApplication();
    app.setDefaultMenuBar(myJMenuBar);
    

    Unfortunately, this is not currently implemented in Java 7. So you may be out of luck. Here is the bug report for this feature: https://bugs.java.com/bugdatabase/view_bug?bug_id=8007267