Java/OS X Lion: Setting application name stopped working with JDK1.7
Asked Answered
M

2

8

I hitherto used the following code to set the Application Name (in the top "System" menu bar) on my Apple MacBook. (Actually, I think I copied this from stackoverflow.)

Basically, have a seperate AppLauncher class that uses System.setProperty() to set the application name before creating a new Runnable for the app itself.

Worked just fine.

However, since I downloaded and started using JDK 1.7, the solution stopped working - I'm getting the Class Name instead of the App Name in the menu, just like before I found that solution. I tried googling it, but to no avail.

Here is the defunct code that used to work under JDK 1.6, reduced to the relevant parts:

public class AppLauncher {
public static void main(String[] args) {

    System.setProperty("apple.laf.useScreenMenuBar", "true");
    System.setProperty("com.apple.mrj.application.apple.menu.about.name",
                "My Application");
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new MainWindow();
        }
    });
}
}

Thanks for suggestions!

ETA: invoking with java -Dapple.laf.useScreenMenuBar=true still works. Pu8tting the property into Info.plist might work, but I haven't tried it yet.

Makeup answered 22/5, 2012 at 12:54 Comment(3)
Any luck with -D or Info.plist, shown here? It may be unsupported in OpenJDK.Swaggering
Hi, yeah the -D seems to do the trick. I will keep Info.plist in the back of my head and try it once I'm there, thanks.Makeup
@trashgod: you should probably add it as an answer so that the question can leave the "unanswered" list.Exemplificative
S
2

It appears that setting the property using -D solves the problem.

java -Dapple.laf.useScreenMenuBar=true …

Other approaches are mentioned in this related answer.

Swaggering answered 30/5, 2012 at 20:53 Comment(0)
G
1

I couldn't get the Info.plist or -D approaches to work (I'm working on distributing a JRuby App, that might have something to do with it), but for me passing the -Xdock:name parameter as mentioned in this article under the section "More tinkering with the menu bar" seemed to work great.

Example: -Xdock:name="My Application"

Gilbertgilberta answered 25/6, 2013 at 20:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.