Skip to main content

Choosing JDK or JDIC System Tray implementation at run-time

1 reply [Last post]
Joined: 2007-07-04

I've found it necessary to choose between the JDK and JDIC implementations of system tray functionality at run-time, depending on the version of the JVM in which my code is running. This is because there's a significant bug in the JDIC system tray implementation for Java 6 on Windows (see ), and of course the JDK doesn't have system tray support prior to Java 6.

I wrote some code that encapsulates this variability and enables a client to abstractly instantiate a system tray icon and make changes to its popup menu, without dealing with the two underlying implementations. The JDK implementation is chosen for Java 6 or later (for future compatibility), and the JDIC implementation is chosen for versions prior to Java 6.

I encapsulated the popup menu and menu item components as well as the system tray and tray icon components, since awt and swing components are used respectively by the JDK and JDIC system tray implementations. The code includes an interface for a tray control object, JDK and JDIC-based implementations of the interface, and a factory class that returns the appropriate implementation for the JVM version. There's also an enum class that defines all the menu items abstractly, so the client can work with them independent of the implementation. I coded the enum class to represent menu items needed for the demo program that's also included. It can be adapted for other uses by defining fields that represent the desired menu items.

The code is available at Just click on the "Source Code" link, and then click the link for "Tray Control".

Message was edited by: midnightjava

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2007-06-04

Well done!