How do I control the display of a JComponent's Tooltip?

前端 未结 2 1626
情书的邮戳
情书的邮戳 2020-12-21 02:44

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.

Th

相关标签:
2条回答
  • 2020-12-21 03:05

    To solve your first issue of where the tooltip doesn't follow the mouse, if you override the getToolTipLocation(MouseEvent e) in JComponent, you can return the point for where you want to the display the tooltip. The MouseEvent will allow you to retrieve the x and y.

    0 讨论(0)
  • 2020-12-21 03:12

    Take a look at the 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.

    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.

    0 讨论(0)
提交回复
热议问题