 |
Continuation tooltips for JLists and JTrees
Posted by timboudreau on August 21, 2006 at 02:30 PM | Comments (8)
A bit before NetBeans 5.0 was out, I wrote support for completion tooltips for JLists and JTrees for NetBeans' Explorer components. It's not at all NetBeans-specific - it can be used for any JList or JTree.
What it does is relatively simple - provide tooltip-like popup(s) that are painted by the list or tree's cell renderer. If necessary it will provide two tooltips - one on the left, and another on the right.
The source code can be found here - all you do is call
ViewTooltips.register (theComponent);
where theComponent is a JList or a JTree. The code was written in expedience mode, not prettiness mode, but it has been in NetBeans since 5.0, is stable, and pretty useful, as such tooltips are rather slick and nice to have.
Writing it was a bit of an adventure - the basics were simple until I tried the code out on my Mac. There, heavyweight popups have drop shadows- exactly what you don't want around something that is supposed to look like it's part of another component.
There are two solutions to the problem: The simple one, which works 60-70% of the time on Mac - which is just writing a custom PopupFactory which prefers lightweight popups when possible. But this doesn't entirely work, as the mac implementation will sometimes recycle a heavyweight popup. Both can be found here.
The second solution, that works 100% of the time, is the egregious hack (see the aptly named inner class, EgregiousHack with its giant wad of reflection code), which commits the no-no of requiring Apple's Cocoa-Java, digging up the native window using Cocoa via reflection and forcing it to have no shadow. This is disabled by default in NetBeans, as who knows what the fate of Cocoa Java will be, long-term, but can be turned on.
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
But couldn't you use only one tooltip, just going above the original text, instead of two pieces popping up at the sides?
Posted by: ronaldtm on August 21, 2006 at 04:03 PM
-
You could - in fact, that's what the first draft of it did. But then you have to proxy events from the tooltip to the tree or list; and there are cases such as when a left-side tooltip would go offscreen, that there should be a truncated version even in such a tooltip. Doing two tooltips this was simpler.
Posted by: timboudreau on August 22, 2006 at 12:51 AM
-
I needed something like this a while back and came across the datatips project. It worked pretty well for my basic needs and limited time. It looks like it has the same sort of pattern as your implementation
Posted by: hopeless on August 22, 2006 at 03:14 AM
-
So, would you like to be able to send hints to the Mac OS X Aqua Look and Feel, to ask that some specific tooltips should or should not have opacity/shadows? Perhaps via a client property on the tooltip? You could always file a bug requesting this functionality.
Posted by: swingler01 on August 22, 2006 at 11:55 AM
-
Hints to make Aqua L&F do that would be nice. I've talked about it briefly with one of Apple's JDK engineers - but they do have bigger fish to fry.
Posted by: timboudreau on August 22, 2006 at 03:55 PM
-
Check the latest release notes for Aple's JDK6... perhaps such a hint is closer than you think.
Posted by: swpalmer on August 22, 2006 at 05:26 PM
-
That would be lovely. Now, if I could just get JFrames with NSDrawer and NSPanel peers, I could do a *really* native windowing impl for mac :-)
Datatips indeed looks similar. No idea which predates which, since what I've got here is over a year old. Looks like they also support JTable, which this doesn't currently.
Posted by: timboudreau on August 23, 2006 at 02:16 AM
-
Very nice method. I just test it with right-to-left JTree/JList and i found that it add one charactor i.e. you will see two same charactors in the border. In addition the position of the tooltip is one pixel up (if I'm not wronge).
Posted by: abdulla on August 23, 2006 at 03:47 AM
|