问题
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