JavaFX application hide OSX dock icon

 ̄綄美尐妖づ 提交于 2020-01-02 16:23:10

问题


I need to hide the dock icon of my javafx application. In a normal java application this can be achieved by the following property:

System.setProperty("apple.awt.UIElement", "true");

However, this does not seems to work with JavaFX.

Thanks!


回答1:


Just tried it. You have to modify *.app/Contents/Info.plist and add

<key>LSUIElement</key>
<string>1</string>

Simple example:

    <?xml version="1.0" ?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
     <dict>
     <key>LSUIElement</key>
    <string>1</string>
...

For me it worked on bundled javaFX apps




回答2:


According to JavaFX you cannot hide dock icon in JavaFX application. Please view this link.

There are two ways to hide dock icon.

  • Apple standard way, just modify *.app/Contents/Info.plist and add <key>LSUIElement</key> <string>1</string>.
  • Start your application as AWT application and hide dock icon using system property. After setting system property call the JavaFX main method and JavaFX application will take over now with no dock icon. Please see the sample code snippet below.
/**
 - This class is intended to start application as AWT application before initializing
 - JavaFX application. JavaFX does not support dock-icon-less application so we are 
 - creating JavaFX application from AWT application so that we can achieve the desired
 - functionality.
 - */

public class AWTMain {

    public static void main(String[] args) {

        // This is awt property which enables dock-icon-less
        // applications 
        System.setProperty("apple.awt.UIElement", "true");
        java.awt.Toolkit.getDefaultToolkit();

        // This is a call to JavaFX application main method.
        // From now on we are transferring control to FX application. 
        FXMain.main(args);
    }
}

Here FXMain is referred as previous class with main method.

You will also need to modify your .pom file if you are using maven and other places too where you have mentioned main class for application.

This is my first answer here so sorry for formatting.



来源:https://stackoverflow.com/questions/24312260/javafx-application-hide-osx-dock-icon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!