在 Java 程序中,我对 JTable 中的单元格使用自定义渲染器。
在此渲染器上,我设置了一个工具提示,其内容取决于当前单元格。
当值不同时,工具提示会更新,并将出现在单元格上方鼠标指针旁边。
但是,当更改单元格时此工具提示的文本相同时(碰巧有几个单元格的工具提示文本相同),TooltipManager 会认为工具提示没有更改,并将前一个工具提示保留在上一个位置。
有人知道如何制作,以便即使具有相同的值,工具提示也会在每个单元格上更新吗?
In a Java program, I am using a custom renderer for cells in a JTable.
On this renderer I set a tooltip, for which the content depends on the current cell.
When the values are different, the tooltip is updated, and will appear next to the mouse pointer, over the cell.
However, when the text for this tooltip is identical when changing cell (it happens that a few cells have the same text for tooltip), the TooltipManager considers that the tooltip hasn't changed, and it leaves the previous one, on the previous position.
Does someone knows how to make it so that the tooltip would be updated on each cell, even with identical values?
发布评论
评论(3)
我认为你最好的选择是覆盖 getToolTipLocation(MouseEvent) 在您的组件中,并让它跟踪鼠标的位置。如果工具提示的文本或位置已更改,则工具提示将更新。
I think your best bet is to override getToolTipLocation(MouseEvent) in your component, and have it track the location of the mouse. If either the text or the location of a tooltip have changed, then the tooltip will update.
添加或删除零宽度、不间断空格?
Add or remove a zero-width, non-breaking space?</hack>
尝试使用 CellStyle 进行工具提示更新:
Try to use CellStyle for tooltips update: