Question

I have a slight problem. Having recently migrated on Mac, I've been pulling my hair and searching the web about this but have not found what I was exactly searching for. I want to set the application name in the system menu, which doesn't work at the moment (my main class name is displayed instead of my app name). What property should I modify?

I have successfully placed my menu in the system menu bar using the correct apple.laf property, but I haven't found what I needed for the name.

My search led me to Info.plist documents, on which I have no knowledge whatsoever. I tried to make a simple one that would only change the app's display name, but for some reason it hasn't worked. Help?

Was it helpful?

Solution

Try using the included Jar Bundler, which is there to handle all this stuff for you. And if you want to see how any particular feature works, you can inspect Jar Bundler's output.

OTHER TIPS

According to sun's documentation you would pass the name into the virtual machine as a command line parameter to the java command with -Xdock:name="{AppName}" replacing {AppName} with what you want to appear as the title in the Menu bar.

Edit: I do not believe that you can set this in the actual Java code itself, but as Chuck said Apple does have a program Jar Bundler which is designed to create the jar with the Info.plist that you need. According to the user guide for it, you need to set the Bundle Name property on the properties pane to get what you want.

There is two ways:

  1. when you call: java -Xdock:name=myAppName
  2. In run time before any GUI interaccion:

    System.setProperty("com.apple.mrj.application.apple.menu.about.name", "myAppName!");
    

Settings any of the proposed Java (with -D in the launch shell script) properties didn't work for me, because they're only for AWT & Swing GUIs. Even the Mac specific -Xdock:* options did't work.

What did work is using this Project https://github.com/codecentric/NSMenuFX

In my JavaFX Controller for the menu I added the following snippet:

  public void initialize() {
    if ("Mac OS X".equals(System.getProperty("os.name"))) {
      final MenuToolkit tk = MenuToolkit.toolkit();
      final Menu defaultMacApplicationMenu = tk.createDefaultApplicationMenu("My App");
      tk.setApplicationMenu(defaultMacApplicationMenu);
    }
  }

Now the bold name of the Menu itself cannot be set using this library, but you can control that setting CFBundleDisplayName in the Info.plist of your application bundle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top