Adding MenuBar Space on Mac

2019-09-18 17:59发布

问题:

On a PC, this issue would not arise, but I have a mac and the java menu bars typically appear on the top left hand area of the screen. For example (from the apple developers website):

The blue highlighted menu is the same name as the main class in a java program. I was wondering how I could name my main method class with a space in between two words rather than an underscore.

回答1:

I tried...

  • Using the -Xdock:name="My App Name" on the command line
  • System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Not My Mac App"); within the main method before before and after setting the look and feel

Only -Xdock:name worked.

Tested using Java 8 on 10.9.4, so the settings might be different for earlier version of Java and OS combinations

You may also consider creating a proper Mac .app bundle, which should allow you to set these properties via the plist file...

Take a look at Packaging a Java App for Distribution on a Mac. It is "slightly" out of date, but should lead you in the right direction