I\'m trying to change the application name displayed into the menu bar of OS X but i can\'t succeed with that. I have tried settings as the first statement in the main metho
Creating class that only has main method allows you to change application name.
Apparently, you can do it adding the following when you add the following options to the command line:
-Xdock:name="Alessio"
While com.apple.mrj.application.apple.menu.about.name is the right property name, I think you'll be setting it too late. Have you tried it on the command line as:
-Dcom.apple.mrj.application.apple.menu.about.name=Alessio
For more information about writing Java Apps for OS X: http://www.oracle.com/technetwork/articles/javase/javatomac-140486.html
It may also be worth looking at something like this: http://launch4j.sourceforge.net/
try to put System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Alessio");
on your main
code before anything else
Using JDK8, you can set the apple.awt.application.name
property to affect the Application menu name.
However, Martijn Courteaux’s warning still applies: you must do this before any AWT classes are loaded. And AWT classes will be loaded before your main()
method runs if it lives in a subclass of JFrame
.
Reference:
http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/5c1d06cd7d7b/src/macosx/native/sun/osxapp/NSApplicationAWT.m#l157
I'm not sure if this also works for OS X Lion, but I'm on Mountain Lion.
After some testing, my conclusion is that you can use the old approach if and only if you don't do anything with
java.awt.Toolkit
before setting the app name.
Some things that use Toolkit are: (Feel free to edit this answer and add items)
java.awt.Font
(@see static initializer of Font)main
method)I've had the same problem and discovered this: if your main
method is a member of one of your GUI classes (for example, one derived from JFrame), when the JVM loads your class it will also need to load some other AWT classes. These can interact with java.awt.Toolkit in static initializers, which, as Martijn observed, causes the property to be checked before your main method has had a chance to set it.
Try moving the main method into a separate class that doesn't extend any Swing or AWT classes and see if it works.