Java Swing question.
I have a JPanel which displays a graph. When I move the mouse over this graph, I want certain information to be displayed on a tooltip-like widget that moves with the mouse. How can I best implement this?
I guess my problem will be solved if I know how to position a custom JComponent absolutely within the JPanel that acts as my drawing canvas. I could then trap the mouse moved event and reposition/update the widget. Any other solution (including possibly using JToolTip directly) would also be very much welcome!
Apologies if this question is a little basic. It's been a really long time since I last used Swing, so I'm still re-learning how to work with it. Many thanks in advance!
Override the
getToolTipText(MouseEvent)
method to dynamically set the tool tip based on the mouse location.Edit:
If you want the tooltip to continually move with the mouse then you will also need to override the
getToolTipLocation()
method.