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!
Joined: Oct 13, 2005
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.
Joined: Jun 09, 2003
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
Joined: Jan 30, 2010
Thank you for your answers!
Ritchie good explanation, now it is makes it much more clearer!
And Michael, I will try with mousePressed !