Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A low-level JNI MacOS menu bar integration for Java
Objective-C Java C
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src-native/jni/tray
src/org/jdesktop/jdic/tray/internal/impl
Makefile
README.md
build.xml
pom.xml

README.md

jdic-macos-tray

This is a simple-low level menubar integration for Java using a compiled native library. Java6 already has cross-platform tray support, however the MacOS implementation doesn't allow the usage of template images, which makes the menu bar icon stand out badly.

In order to overcome that limitation jdic-macos-tray uses a compiled native library to directly access the Cocoa API. It's based on the original jdic project, which now seems to be dead - I just ripped off the minimal set of classes needed for the menu bar functionality and made some modifications since the original implementation used Swing JPopupMenus, which looked and behaved badly.

For alternatives, take a look at SWT.

Building

Checkout the source, then call make:

make

That's it. Check the dist folder.

Usage

First get an instance of the system tray:

MacSystemTrayService tray = MacSystemTrayService.getInstance();

Create a status item / tray icon, optionally passing in an ActionListener:

MacTrayIconService icon = new MacTrayIconService();

Set a caption or an image and add to the system tray:

icon.setCaption("App menu");

// alternatively
icon.setIcon(...);

tray.addTrayIcon(icon, 0);

Now add some menu items to the status item:

icon.addItem("Item 0", new ActionListener() {...});
icon.addItem("Item 1", new ActionListener() {...});
icon.addItem("Item 2", new ActionListener() {...});

Removing items is equally as easy:

icon.removeItem(2);

License

GPL

Something went wrong with that request. Please try again.