How to change the Java application name shown in the Mac OS X launchpad
Asked Answered
R

4

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.

Rashad answered 18/2, 2017 at 19:7 Comment(0)
S
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

Sternwheeler answered 22/2, 2017 at 6:46 Comment(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.Rashad
L
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

Loyceloyd answered 4/9, 2020 at 14:18 Comment(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.Loyceloyd
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.Rashad
I
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

Igor answered 1/3, 2017 at 5:25 Comment(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...Rashad
A
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)
Airlie answered 26/2, 2017 at 21:29 Comment(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.Rashad
@m.vokhm And did you call setAppName before everything is created?Potful
@Potful 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.Rashad

© 2022 - 2024 — McMap. All rights reserved.