开发者

SystemTray based application without window on Mac OS X

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

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 {
            tra开发者_开发知识库y.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

    }
}
}

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


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/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜