Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ToolTip text is not being updated  RSS feed

 
Janus Engstrøm
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi fellow ranchers,

I've stumbled across yet another small annoyance, this time when using ToolTips.
Say you have a JTable with ToolTipText enabled for a specific column. The text for the ToolTip for that column is the same, say "Click for combobox". When hoovering over first row in that column the tool tip appears correctly, but when moving the mouse cursor any of the following rows in same column, the tool tip doesn't follow the cursor.

An example is here. Try to hoover on elements in the "Sport"-column.

When the tool tips aren't the same (as is toolTip_rowA.equals(toolTip_rowB) ) the location of the tool tip popup is updated correctly.

I've tried the following to force this update:


-but that doesn't work.

Anyone with a good idea to how to force the popup to move, when cursor is moved onto another row with same tool tip as the previous?


With kind regards,
Janus
 
Rob Spoor
Sheriff
Posts: 21044
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Table, list and tree cell renderers are not actually used as components, but are only used to paint the cell contents. That means that their tooltips won't work directly. Instead, they are called from the JTable's getToolTipText(MouseEvent) method. And that method says this:
Overrides JComponent's getToolTipText method in order to allow the renderer's tips to be used if it has text set.

Note: For JTable to properly display tooltips of its renderers JTable must be a registered component with the ToolTipManager. This is done automatically in initializeLocalVars, but if at a later point JTable is told setToolTipText(null) it will unregister the table component, and no tips from renderers will display anymore.
 
Janus Engstrøm
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,

Actually, using setToolTipText(null) doesn't do any difference. The problem is the same whether or not is is called. The tool tips still appear even when using the null-value.
Since it didn't do anything, I removed it again.

Problem still persists: If 2 consecutive rows has the same tool tip, the ToolTipMananger doesn't update the tool tip popup. It remains in the same place when mouse cursor is moved to another row (having the same tool tip), just as the example quite nicely shows.

Kind regards,
Janus
 
Janus Engstrøm
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Janus Engstrøm wrote:
Actually, using setToolTipText(null) doesn't do any difference. The problem is the same whether or not is is called. The tool tips still appear even when using the null-value.
Since it didn't do anything, I removed it again.


Actually, it does do something: If the text is empty ("") in the setToolTipText, it shows a small square as the tool tip, which I presume is the border around the label for the tooltip. By setting the toolTipText to null, that square disappears.

 
Rob Spoor
Sheriff
Posts: 21044
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was not talking about setToolTipText for the renderers but for that of the JTable. Have you also registered the JTable with the ToolTipManager as the text I quoted suggested?
 
Janus Engstrøm
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,

Isn't that way described by you just one of several ways to handle tool tips for JTables?

Well, I've tried it, it produces the same result: If tool tips are equal, the location of the popup doesn't change.


This doesn't work correctly:




This does work correctly:



Perhaps it's a performance feature implemented in the ToolTipManager .. ?


Regards,
Janus
 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you could try overriding the getTooltipLocation() method.

Or, maybe in the renderer after after resetting the tooltip you invoke TooltipManger.mouseMoved() event to fake a mouse move so the tootip actually gets updated and the repeat when you reset the tooltip back to its real value.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!