SystemTray based application without window on Mac OS X

不问归期 提交于 2019-12-06 15:13:41

问题


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 {
            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

    }
}
}

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


回答1:


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


来源:https://stackoverflow.com/questions/5057639/systemtray-based-application-without-window-on-mac-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!