3

I want to be able to set the dock:name of my Java application on a Mac.

I know that I can do it through the -Xdock:name="Xyz" option to the Java VM, but I would like to do it directly in my program.

According to this question it can be done by setting the "com.apple.mrj.application.apple.menu.about.name" property, but I simply cannot get that to work.

Consider this program:

import javax.swing.*;

public class Abc extends JFrame {
    public Abc() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(200, 200);
        setVisible(true);
    }

    public static void main(String[] args) {
        try {
            System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Xyz");
            System.setProperty("apple.laf.useScreenMenuBar", "true");
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch(Exception e) {
            System.out.println("Exception: " + e.getMessage());
        }

        SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    new Abc();
                }
            });
    }
}

I would have expected that to work, but it doesn't. I'm using OS X 10.8.2 (Mountain Lion) and Java 1.7.0_09, both of which are very new versions. Perhaps the API has changed?

What am I doing wrong?

Community
  • 1
  • 1
oz1cz
  • 5,504
  • 6
  • 38
  • 58
  • See also this [Q&A](http://stackoverflow.com/q/8955638/230513). – trashgod Nov 02 '12 at 11:48
  • trashgod, you link to a relevant Q&A, but I'm unsure about which part of the Q&A you are referring to. I tried compiling and running the code in your accepted answer; but on my computer, the application menu says "NewMain", not "Name" as it does in the screenshot you show. – oz1cz Nov 02 '12 at 12:07
  • Sorry, I don't have a 10.8/1.7 instance to test. Be sure you are using `com.apple.laf.AquaLookAndFeel`; otherwise, I know it fails on older versions. – trashgod Nov 02 '12 at 12:56
  • I _am_ using `com.apple.laf.AquaLookAndFeel`. – oz1cz Nov 02 '12 at 13:00

0 Answers0