12

When my application written in Java with SWT runs under OS X, both from under Eclipse and from jar, its name in the launchpad reads "java", like shown in the picture.

wrong app name shown in the launchpad

In the beginning of my code I call Display.setAppName("MyApp"), and the name of the application in the menu bar and menu items is correct, it reads MyApp, About MyApp, Configure MyApp, etc. The menu items behave properly, I can receive and handle the appropriate events. So the problem pertains exclusively to the app name, shown in the launchpad. Is there any way to set the correct name to be shown in the launchpad programmatically, from the code, without creation of the application bundle?

P. S. The code is actually running under JVM that is started from within my code using ProcessBuilder:

  new ProcessBuilder("java -cp mypath MyClass my args").start();

a kind of recursion, needed to compute some jvm options and classpaths programmatically before starting the application.

4 Answers 4

3

You should create a macOS app bundle with your jar, where you can put the bundle display name in the Info.plist file of the bundle.This is well documented by Oracle (http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html).

The structure of a Java app bundle is documented by Apple as well: https://developer.apple.com/library/content/documentation/Java/Conceptual/Java14Development/03-JavaDeployment/JavaDeployment.html

1
  • Thank you, but I'm searching for a way to achieve this goal without creating an application bundle. I would like to fix the app name programmatically, from the code. It's a requirement imposed by the customer -- the application should be a single jar, that must run in Windows, Linux and Mac equally well. Currently it does, and the only thing I don't like is this app name shown in the launchpad.
    – m. vokhm
    Commented Feb 23, 2017 at 4:38
2

The only answer that worked for me is here. In short:

Using JDK8, you can set the apple.awt.application.name property to affect the Application menu name.

However, Martijn Courteaux’s warning that you must do this before any AWT classes are loaded still applies. And AWT classes will be loaded before your main() method runs if it lives in a subclass of JFrame.

In other words, set apple.awt.application.name and do it before creating the JFrame.

P.S. If you're trying to change the dock application title, this command might work:

java -Xdock:name=Alfabet

2
  • I'm aware this only changes the menu bar title, and is for AWT, but this question is the first result for how to change the application name, so I thought I would at least link to the proper question and answer for this. Commented Sep 4, 2020 at 14:22
  • 4
    Thank you, but it doesn't solve the issue I wrote about. In my case, the name displayed in the menu is OK, what's wrong is the name that appears in the pop-up when the cursor hovers over the application's icon in the launchpad. It reads java instead of the application name, as shown in the picture. -Xdock:name=Alfabet does not help either.
    – m. vokhm
    Commented Sep 6, 2020 at 7:55
1

@m. vokhm I hope you have tried the following link

http://www.eclipse.org/articles/Article-Branding/branding-your-application.html

Also Check "3. How a launch can be triggered" in the link below

http://www.vogella.com/tutorials/EclipseLauncherFramework/article.html

1
  • The links are interesting, but my application is pure SWT application, not a RCP, so I don't know how can I use this information in my case...
    – m. vokhm
    Commented Mar 1, 2017 at 8:02
0

You should do the following during app initialization, before GUI is built:

// take the menu bar off the jframe
System.setProperty("apple.laf.useScreenMenuBar", "true");

// set the name of the application menu item
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "AppName");

// set the look and feel
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

But above code works in Java 1.5, this code may not work in 1.6

For new java see documentation:

  1. Either use -Xdock:name command-line property:-Xdock:name=YourAppName
  2. Or set CFBundleName in information property list file (plist)
3
  • I use SWT, not AWT/Swing, so playing with lafs makes no sense. -Xdock:name works, but it only works for the app name shown in the menu bar. And there is a simpler way to do it: Display.setAppName(myAppName) does exactly the same. None of these tricks affects the name that is shown next to the app's icon in the launcher, so they don't solve my problem.
    – m. vokhm
    Commented Feb 27, 2017 at 12:09
  • @m.vokhm And did you call setAppName before everything is created?
    – Hrabosch
    Commented Feb 28, 2017 at 9:55
  • @Hrabosch Yes, I did, and it works for the menu, but not for the launchpad, as I implied above. I have edited the question to express it clearer.
    – m. vokhm
    Commented Mar 1, 2017 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.