Change the application name at runtime on Mac for

2019-02-14 03:00发布

Please take a look at this image: http://i.imgur.com/pHIg1AA.png Is it possible to change the application name ("My JavaFX-based Mac App") in the Mac OS X system menu bar at runtime after the app starts? If it's not possible to change at runtime, is there a way to change it after app restarts? I think that name came from Info.plist. The app is built using JavaFX ant task for Mac OS X.

Thanks.

4条回答
可以哭但决不认输i
2楼-- · 2019-02-14 03:20

Actually, you can change it very easily by using the java-command args
-Xdock:name=SomeName

This works fine for me, launching a JavaFX application on a Java11 custom-built runtime with a bash-script as a native application.

From the Oracles Java 10 documentation:

-Xdock:name=application name
Overrides the default application name displayed in dock. [*]

-Xdock:icon=path to icon file
Overrides the default icon displayed in dock.

[*] Also affects the menu name.

You can see my complete command by looking for 'src_macos/tmpl/George.sh' here: https://bitbucket.org/andante-george/george-application/src

For the About-dialog simply do do: java.awt.Desktop.getDesktop().setAboutHandler(my_about_handler). In your handler open whatever kind of dialog or window you want.

查看更多
Rolldiameter
3楼-- · 2019-02-14 03:27

I'm aware of two methods of achieving what you want:

1) Call javafx.awt.Desktop.getDesktop from the main thread before creating any stages:

object MYAPP
{
  def main(args: Array[String]) =
  {
    val d = java.awt.Desktop.getDesktop

    // ...optionally, add handlers for interesting desktop events

    javafx.application.Application.launch(classOf[MyApp], args: _*)
  }
}

I believe, among other things, this renames the application menu to MYAPP.

2) Package your application using the javapackager tool.

查看更多
老娘就宠你
4楼-- · 2019-02-14 03:43

When using javafx-maven-plugin you can specify it in your pom.xml like this:

<plugin>
  <groupId>com.zenjava</groupId>
  <artifactId>javafx-maven-plugin</artifactId>
  <version>8.6.0</version>
  <configuration>
    <appName>Aaa Working Title</appName>
    ...
  </configuration>
  ...
</plugin>
查看更多
\"骚年 ilove
5楼-- · 2019-02-14 03:47

That should work as is always worked for me :D

primaryStage.setTitle("LOLOLOLOL");

This changes your window's name. You can change this value at any time, if you have the Stage element at your disposal.

查看更多
登录 后发表回答