本文介绍了无窗在Mac OS X基础的SystemTray应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何做,只运行一个SystemTray中的TrayIcon在Mac OS X的应用程序,(没有一个AWT窗口和停靠图标)?

How do I do an application that runs only as a SystemTray TrayIcon on mac os x, (without an awt window and dock icon)?

在code我使用的是这样的:

The code I'm using is this:

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

The problem is I'm getting a dock icon with title com.cc.ew.App

推荐答案

要在码头,你必须prevent图标C>文件添加布尔键 LSUIElement 并将其设置为YES。

To prevent icon in dock, you must in <your-app>-Info.plist file add boolean key LSUIElement and set it to YES.

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

这篇关于无窗在Mac OS X基础的SystemTray应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 21:40