Challenge

I want to have an icon in the SystemTray of Mac in order to sync some calendar stuff.

Extra information

I came to this solution via this code snippet Before finding this snippet I have tried a variety of options, namely: ScalaFx, JavaFx, Swt, com.dorkbox.SystemTray.

ScalaFx/JavaFx can handle native menu’s via the menuBar.setUseSystemMenuBar(true);. This only puts the menubar on the left side, and disappears when I switch between applications.

When using Swt or com.dorkbox.SystemTray I do manage to have an icon in the systemtray, but the look and feel is not the same as any native app does.

In this example you will get a green square in the screen because then the code is independent from external images. I have included a comment for getting an image from disk.

Remove Doc Icon and from cmd+tab

If you want to remove the cmd+tap java item still visible just add -Dapple.awt.UIElement="true" to your startup script as a VM argument, or you can set a property in the Info.plist as:

Also you can use System.setProperty("apple.awt.UIElement", "true"); in your code but strangely it does not seem to work for me. If you do know how to make that work please leave a comment below.