Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 576
Bet Lamed Avatar asked May 22 '12 12:05

Bet Lamed


People also ask

Where is Java_home on Mac?

JAVA_HOME is essentially the full path of the directory that contains a sub-directory named bin which in turn contains the java. For Mac OSX – it is /Library/Java/Home.


1 Answers

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

java -Dapple.laf.useScreenMenuBar=true …

Other approaches are mentioned in this related answer.

like image 159
trashgod Avatar answered Oct 09 '22 16:10

trashgod