简体   繁体   中英

JavaFX application hide OSX dock icon

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!

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM