【问题标题】:SystemTray based application without window on Mac OS X基于 SystemTray 的应用程序,在 Mac OS X 上没有窗口
【发布时间】:2011-02-20 14:36:43
【问题描述】:

如何在 mac os x 上创建仅作为 SystemTray TrayIcon 运行的应用程序(没有 awt 窗口和停靠图标)?

我使用的代码是这样的:

public class App
{   
public static void main( String[] args )
{
    final TrayIcon trayIcon;

    if (SystemTray.isSupported()) {

        SystemTray tray = SystemTray.getSystemTray();
        Image image = Toolkit.getDefaultToolkit().getImage("tray.gif");

        trayIcon = new TrayIcon(image, "Tray Demo");

        trayIcon.setImageAutoSize(true);


        try {
            tray.add(trayIcon);
        } catch (AWTException e) {
            System.err.println("TrayIcon could not be added.");
        }

    } else {

        System.out.println("Tray is not supported");
        //  System Tray is not supported

    }
}
}

问题是我得到一个标题为 com.cc.ew.App 的停靠图标

【问题讨论】:

  • 你的问题是什么?怎么了?
  • 我在扩展坞上有一个托盘图标和一个 Java 应用程序,而不仅仅是托盘图标。我将编辑问题并澄清

标签: java macos user-interface awt trayicon


【解决方案1】:

要防止图标出现在 Dock 中,您必须在 <your-app>-Info.plist 文件中添加布尔键 LSUIElement 并将其设置为 YES。

<key>LSUIElement</key>
<true/>

【讨论】:

  • 是的,这是标准的 macOS 约定。所有应用都这样做。
猜你喜欢
  • 1970-01-01
  • 2011-07-26
  • 2021-12-13
  • 1970-01-01
  • 2011-11-19
  • 1970-01-01
  • 1970-01-01
  • 2011-07-15
  • 2013-07-20
相关资源
最近更新 更多