I am trying to create a tool tip which will be displayed on painted text using graphics.
I am stuck because i do not know how to proceed.
i have achieved this so far:
The text "Show Me", "One", "Twozzzz" should be displayed as Tool Tip when hover.
I have tried using MouseMotionAdapter and then add the tool tip but it can not be displayed because the data "Show Me", "One", "Twozzzz" is moving and changes every time.
Hence when i try to display it again i can not!
i did not really get and i tried in vain your solution.
But here is my sample implementation and i am really looking forward if someone could help me with at least new ideas on how to make this work.
The idea is that the values from method getString *forgot to change* have to be displayed when mouse is over component.. The values can change at anytime when the window has been re-sized just as in this one.
I would also like to make the size of the paintedComponent to be same as the size of the value from the getString()**
How can i make the toolTip work in this case??
I should display the tooltip when use is over lets say 0.21201 value??
The paintComponent() method will be called whenever Swing determines a component needs to be repainted. You painting code doesn't make sense because you calculate a random value. This logic should never exist as part of the painting code. It will change every time Swing decides to repaint the component.
Swing also supports borders, foreground and background colors. To use a JLabel for this you first need to make the label opaque and then your code would be something like:
The text color defaults to a shade of BLACK so you don't need to set that.
Thats all you need.
Again if this doesn't work for you then post a proper SSCCE that demonstrates your problems.