如何控制JComponent的Tooltip的显示? [英] How do I control the display of a JComponent's Tooltip?
问题描述
我有一个JComponent,它自己绘制各种形状。我正在检测鼠标何时输入其中一个形状并相应地更改工具提示。
I have a JComponent that's painting various shapes on itself. I'm detecting whenever the mouse enters one of these shapes and changing the tooltip accordingly.
我遇到的问题是:
- 当用户在形状上跟踪鼠标时,工具提示不会跟随鼠标。
保持在第一次设置的位置,然后只有在另一个形状改变工具提示时才会跳转。 - 工具提示出现需要大约一秒钟,但我想要它立即出现。
有人可以建议一种在不编写自定义工具提示机制的情况下获得这些行为的方法吗?
Can someone suggest a way of getting these behaviours without writing a custom tooltip mechanism?
推荐答案
看看 ToolTipManager 。
您可以向该经理注册您的组件,然后调整一些设置。它非常直接使用。
You can register your component with that manager and then adjust a number of settings. Its pretty straight forward to use.
这至少可以解决你的初始延迟问题。
That at least can solve your initialdelay problem.
第一个问题您可以覆盖组件中的createTooltip命令以获取JTooltip实例。每当你移动你的鼠标(也就是你的鼠标)作为它的JComponent类的子类时,它很容易使位置发生变化。
For your first problem you can overide the createTooltip command from your component to get a hold of the JTooltip instance. and then its easy make the position change whenever you move your mouse(aka follow your mouse) as its a subclass of the JComponent class.
这篇关于如何控制JComponent的Tooltip的显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!