Search code examples
javawinapiswingusabilityjava-native-interface

How to notify the user of important events for a desktop application?


Our customer is using our software (Java Swing application started using Webstart) besides other software like MS Office, to do his job. From time to time there are important events he has to deal with in our software without much delay. The customer wants to have a prominent notification then. Now he might be using Excel at the moment, so popping up a message box will not suffice (although the entry in the task bar will be flashing).

We need some mechanism like the Outlook notifier, i.e. a popup that is always visible but does not steal the focus. The notifier should be displayed all the time until the reason for the message has gone (the user has solved the issue) or the user has closed the message (like in outlook). Additionally we want to display a tray icon and maybe play a sound.

I've tried the Java6 java.awt.SystemTray as well as the JDIC (version 0.9 since we already have that lib in the classpath of that project) equivalent, but I did not find a way to set the timeout of the TrayIcon.displayMessage method, and the message seems not to be always on top.

Is there any other option besides JNI to achieve the requested behavior?

If JNI is the only choice and since Windows is the only platform of our customers, is the Outlook notifier an Outlook only feature, or is it freely usable through the Windows API?

Or what other options exist to notify the user about an important task to perform in one software without hindering him to complete his current task in another software. A system modal dialog therefore is no option!


Solution

  • Try using setAlwaysOnTop on your JFrame/JWindow.