简体   繁体   English

JavaFX应用程序隐藏OSX停靠图标

[英]JavaFX application hide OSX dock icon

I need to hide the dock icon of my javafx application. 我需要隐藏我的javafx应用程序的停靠图标。 In a normal java application this can be achieved by the following property: 在普通的Java应用程序中,可以通过以下属性来实现:

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

However, this does not seems to work with JavaFX. 但是,这似乎不适用于JavaFX。

Thanks! 谢谢!

According to JavaFX you cannot hide dock icon in JavaFX application. 根据JavaFX,您无法在JavaFX应用程序中隐藏停靠图标。 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> . 以Apple标准方式,只需修改* .app / Contents / Info.plist并添加<key>LSUIElement</key> <string>1</string>
  • Start your application as AWT application and hide dock icon using system property. 将您的应用程序作为AWT应用程序启动,并使用系统属性隐藏停靠图标。 After setting system property call the JavaFX main method and JavaFX application will take over now with no dock icon. 设置系统属性后,调用JavaFX main方法,JavaFX应用程序将立即接管而没有停靠图标。 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. 此处,FXMain通过main方法被称为上一类。

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. 如果您还在使用Maven和其他提到应用程序主类的地方,则还需要修改.pom文件。

This is my first answer here so sorry for formatting. 这是我的第一个答案,非常抱歉。

Just tried it. 刚刚尝试过。 You have to modify *.app/Contents/Info.plist and add 您必须修改* .app / Contents / Info.plist并添加

<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 对我来说,它适用于捆绑的javaFX应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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