views:

30

answers:

1

When a tool tip is displayed on a tree and the mouse is moved the tooltip stays visible and the text changes. Is it possible to hide the tool tip and redisplay it when the mouse moves from one item to the next.

A: 

Extend DefaultTreeCellRenderer and invoke setToolTipText() as required. The tutorial project TreeIconDemo2, discussed in Customizing a Tree's Display, demonstrates the approach.

Addendum: You can supply the desired text for each node in a TreeCellRenderer, e.g. MyRenderer:

    setToolTipText(value + " is in the Tutorial series.");
trashgod
i've tried that, but the tool tip does not disappear and reappear while moving one each node. the behavior i was trying to acheive was:Mouse over node1 ->show tooltip for node1Mouse over node2 -> hide tooltip for node1, n delay show tooltip for node2
jagguli
@jagguli: It seems to work in the `TreeIconDemo2` mentioned above.
trashgod
@jagguli: Oh, I see; you want the tool tip to come and go. You could use `ToolTipManager.sharedInstance()` and alter the delays.
trashgod
I want the tool tip to disappear on mouse exit from one node,then reappear on mouse enter on the next node, not based on a delay. Maybe something in the tooltipui ?
jagguli
Anyways its not a requirement for us anymore, the main concern was whether having the tool tip visible when mouse moves over a large tree would increase cpu utilization, so far it doesn't seem that way so its ok.
jagguli
@jagguli: For scalability, the flyweight pattern pervades Swing, which uses renderers for many components.
trashgod