Search code examples
javamacosuser-interfaceawttrayicon

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


Solution

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