wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes TooltipText on click Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "TooltipText on click" Watch "TooltipText on click" New topic
Author

TooltipText on click

Nicol Green
Ranch Hand

Joined: Jan 30, 2010
Posts: 66
I used to programmed in .net framework, so some terms I still remember! ;) I am not sure is in java tooltipText same as Hint in C# ?

I see in help that TextToolTip is shown when the cursor lingers over the component. I would like to implement it to show when I click at popup menu (popup menu appears when I click on button with right Mouse button). I suppose it should be possible, and the TextToolTip == Hint.

Maybe my code is working, but shows ToolTipText in the place where I cannot see, if so, how to use getLocation method in this situation to see where it poups ? Please tell me your thoughts. The code:


And why do I need to set menuItem to final ?

Thank you in advance!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
Moving to our GUIs forum.

You are creating an anonymous object of an anonymous class, an ActionListener. Now that ActionListener object will continue to exist after the method has completed. So it will need a reference to any objects it uses. So it copies the reference to that object. Now you have two copies of that object, one used by the method, the other used by the ActionListener. But what if the reference used by the method changes? You now have two references supposedly to the same object, which actually point to different locations. The only way a compiler can verify that the two still point to the same thing is by preventing the copy used by the method changing, which is Java is done with the final keyword.
This is necessary for parameters and local variables, but is not necessary for fields of the class, because the lifetime of a field is no shorter than the lifetime of the ActionListener.

Yes, I believe a tool-tip is the equivalent of a hint.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
mouseClicked is generally a poor choice - it requires the x/y coords of both mousePressed and mouseReleased
to be identical, so, a slight movement of the mouse between press/release and mouseClicked won't fire.

use mousePressed instead
Nicol Green
Ranch Hand

Joined: Jan 30, 2010
Posts: 66
Thank you for your answers!
Ritchie good explanation, now it is makes it much more clearer!
And Michael, I will try with mousePressed !
 
jQuery in Action, 2nd edition
 
subject: TooltipText on click
 
Similar Threads
JPopupMenu or JMenu - neither is quite what I'm after.
ToolTipText Code for AWT and Applet
How to make popup invisible
ToolTipText Code for AWT and Applet
Retrieving tooltiptext from a game....