Help me put my icon in the menubar!
November 11, 2006 1:23 PM   Subscribe

I want the Java application I'm writing to put an icon in the menu bar (next to the system clock, airport status icon, iChat icon, battery icon, etc), a la Quicksilver and Gmail Notifier, but I have no idea how. Help!

I've been googling all afternoon, but the only information I can find relates to a plist entry that directs OS X to place the top-level jframe's menu in the OS X menu bar. While that's nifty, I need the ability to put an icon up there, and not in the dock. Quicksilver's preferences pane calls this a "menu bar icon," but I can't find anything useful in Google with that name. Is there a more proper name for this behavior, and can I achieve it with a Java app?
posted by Alterscape to Computers & Internet (7 answers total)
 
The most common term is menuling. Offiicially, they're called NSMenuExtras or NSStatusItems depending on which API you use to create them. No idea how to do them from Java.
posted by cillit bang at 1:33 PM on November 11, 2006


you are gonna want to google for "system tray", not "menu bar"

I got this link as the second result of a search for "java system tray icon"
posted by blind.wombat at 1:49 PM on November 11, 2006


nevermind, missed the OSX bit...
posted by blind.wombat at 1:51 PM on November 11, 2006


You're going to want to use the com.apple.cocoa.application.NSStatusItem class. It's in the Application Kit.
posted by majick at 2:03 PM on November 11, 2006


Wait for jdk1.6.

The problem is doing this in a cross-platform way. Otherwise you could use JNI to a link to a small mac program in C or C++ that adds an icon to the system tray and notifies your program when it's clicked.

Remember, though, your java program should work on any OS, so it's not a question of "how to do this in OSX" but "how to do this on all OSes" Other then waiting for Java SE6, that would mean writing native class implementations for every OS you wanted your program to work on.
posted by delmoi at 2:03 PM on November 11, 2006


Hmm, actually it looks like you can get JDK6 beta today.
posted by delmoi at 2:05 PM on November 11, 2006


No, you can't. Java 6's "system tray" support doesn't do NSStatusItem -- not to mention, it doesn't have Apple's Application Kit class library. Not to mention Sun JDKs don't have Framework support.

"Remember, though, your java program should work on any OS, so it's not a question of "how to do this in OSX" but "how to do this on all OSes"

Patently untrue. OSX-only Java development is a valid, well-supported platform. It's neat that Java has a handful of cross-platform feature abstractions for a handful of Sun's favorite platforms (of which OSX is not one), but there is absolutely no reason whatsoever to ignore the enormously featureful class library provided by Apple. Apple's intention is for the Java language to be a first-tier choice for "native" application development.

Telling this person "Wait for java.awt.SystemTray" is tantamount to saying "don't develop for OSX, develop for Windows and GNOME." I don't think that answers the question at all.
posted by majick at 8:27 AM on November 12, 2006


« Older How contagious is leprosy?   |   ISO store-bought eggnog recipe Newer »
This thread is closed to new comments.