Tooltips, the mouse wheel and JScrollPane
843807Oct 17 2009 — edited Oct 20 2009Hi,
I've implemented a JTable which provides a cell-dependent tooltip. The table is displayed within a JScrollPane and I've noticed a bug: if I scroll the pane using the mouse wheel, the tooltip isn't affected, it remains relevant for the cell which was under the cursor before scrolling. When I move the mouse slightly, the tooltip updates properly.
In order to implement cell-dependent tooltips, I've overriden JTable.prepareRenderer, but the same problem appears when using the methods described in the tutorial ([http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#celltooltip]). It appears that ToolTipManager ignores MouseWheelEvent's, which is reasonable for most components... but inappropriate for scrollable tables, lists etc.
I did manage to capture the MouseWheelEvent's by using JScrollPane.addMouseWheelListener with my JTable, but haven't found a way to force proper update of the tooltip. Setting the tooltip text of the table seems to have no effect. Passing the MouseWheelEvent to ToolTipManager.mouseMoved() causes the current (and outdated) tooltip to be hidden, but a new one is not displayed until after the mouse is moved to a different position.
I'd really dislike confusing the ToolTipManager with false mouse locations just for this... Is there a better solution to this problem?
TIA
Babelfish