Mac OSX system menu name with Java?

I have a little problem. Having recently moved to the Mac, I pulled my hair and searched the Internet about it, but did not find what I was exactly looking for. I want to set the name of the application in the system menu, which is not working at the moment (instead of the name of my application, my main class name is displayed). Which property should be changed?

I successfully placed my menu in the system menu bar using the correct apple.laf property, but I did not find what I need for the name.

My search led me to Info.plist documents on which I have no knowledge. I tried to make a simple one that would only change the display name of the application, but for some reason it did not work. Help?

+3
source share
4 answers

Try using the included Jar Bundler , which is designed to handle all this stuff for you. And if you want to see how a particular function works, you can check out the output of Jar Bundler.

+2
source

According to the sun documentation, you will pass the name to the virtual machine as a command line parameter for the java command with a replacement -Xdock:name="{AppName}" {AppName}with what you want to display as a title in the menu bar.

: , Java-, , , Apple Jar Bundler, Info.plist, . Bundle Name , , .

+3

:

  • : java -Xdock: name = myAppName
  • :

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

Java ( -D script) , AWT Swing. Mac -Xdock:* .

What worked with 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 this option CFBundleDisplayNamein Info.plistyour application package.

0
source

Source: https://habr.com/ru/post/1717743/


All Articles