|
|
||
Alexander Potochkin's BlogFebruary 2008 ArchivesJTrayIcon updatePosted by alexfromsun on February 14, 2008 at 11:12 AM | Permalink | Comments (21)JDK 6 introduced plenty of cool desktop features, like famous gray-rect fix or advanced drag and drop support,
There have been many blogs how useful new features are,
and I don't want to repeat them. Among all successful and well-designed features there is one which actually has not been completed,
Swing and AWT team work together (by the way, AWT team seats in 10 steps from my room), AWT is responsible for the "native" parts of the code, like topLevel frames, event processing etc,
It wasn't a surprise that TrayIcon feature came to AWT team, and they implemented it perfectly - it works well and it is supported for various Windows, Linux and Solaris systems.
JPopupMenu doesn't extend awt.Popup but it looked like it would be easy to attach JPopupMenu to the trayIcon with help of MouseListener, but it was not the case. The fact is that there is no way (or at least easy one) to correctly attach JPopupMenu to a TrayIcon.
It is our fault, sorry about that. Now let's see how we can solve this problem. To make JTrayIcon possible I fixed three particular bugs for the next JDK 6 update release (the famous update #10, aka 6uN) and for the JDK 7 beta ClassCastException in Swing with TrayIcon If JPopupMenu is shown from a trayIcon's mouseListener an ugly ClassCastException was thrown in some cases. Keyboard navigation problems and highlighting of the first item If popup menu lost focus it stopped processing keyboard events in some cases, the first item a popup was highlighed by default which is very different from any other GUI I've seen Swing Popups should overlap taskbar Finally it was impossible to implement a good looking trayicon's popup menu, because Swing popups couldn't overlap taskbar Having integrated all three fixes I managed to write the JXTrayIcon class which extends java.awt.TrayIcon and contains setJPopuMenu(JPopupMenu) method Here is how JXTrayIcon looks when you click on it, with the current JDK 6 the same code is run under JDK 6 update 10 or JDK 7 The red quarter circle icon is owned by the JXTrayIcon's test. I encourage you to download the JDK 6u10 early bits and try out the JXTrayIcon demo
I particularly interested how it works in different environments,
Thank you and sorry this took so long.I hope it was worth the wait. alexp
| ||
|
|