Search code examples
tooltipdraw2d

Draw2d: How to get a tooltip to stay longer


I have a program that creates tooltips using Figure.setToolTip(). Everything works great except that the tooltip disappears after a few seconds. The tooltip can contain a lot of information and I would like the tooltip to stay longer (or even indefinitely, until the cursor exits the figure).

I haven't found any methods or fields in the ToolTipHelper class that deal with this. Is this even possible to do?

The only other work around I can think of is to simply display a figure with the tooltips inside upon mouseEnter() and hide it on mouseExited(). But I would much rather use the built in tooltip feature.


Solution

  • I ended up using PopUpHelper which is the super class of ToolTipHelper. I simply added a MouseMotionListener to the Figure and on mouseEntered(MouseEvent arg0) and mouseExited(MouseEvent arg0) called tooltipHelper.show() and tooltipHelper.hide().

    By calling getLightweightSystem().setContents(IFigure) and setShellBounds(int,int,int,int) in PopUpHelper I could determine what to display and where to display the tip.

    The pros are the tip stays as long as my cursor is inside the figure. The tooltip is also the same size regardless of the scale of the canvas (this was stopping me from simply adding a Figure to the canvas and calling setVisible() and setLocation()).

    Cons are you have to do most of the work yourself (the work ToolTipHelper was meant to do). This includes hiding the tooltip in some unusual instances (such as, in my case, switching tabs while the mouse is still on the Figure) and coding the tooltip location to not run off screen.