Home arrow static arrow Java Programming [Archive] - Force a ToolTip to show itself?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Force a ToolTip to show itself?
This topic has 9 replies on 1 page.

Posts:105
Registered: 6/8/04
Force a ToolTip to show itself?  
Aug 4, 2004 6:36 AM



 
Greetings, all.

I'd like to allow a user to right-click on certain areas of my Applet, and, upon right-clicking, have a ToolTip display until they move their mouse, at which point it disappears. I've been searching through the JToolTip and ToolTipManager API's, but haven't been able to find a way to do this. JToolTip.setVisible() doesn't seem to display it, and if I set the delay before showing ToolTips using the ToolTipManager to zero, the user has to move their mouse and then bring it to rest before a ToolTip displays.

Right now, I'm thinking that I may need to just paint a ToolTip-like box on my Applet, but I'd rather be able to use an actual ToolTip, since those can (if'n I'm not mistaken) extend beyond the confines of the Applet, and the ToolTips I'm trying to display may be rather long.

Does anyone know of a way to make a ToolTip appear at a specific event?
 

Posts:105
Registered: 6/8/04
Re: Force a ToolTip to show itself?  
Aug 4, 2004 7:05 AM (reply 1 of 9)



 
...nobody loves me : (...

Maybe I should try this in Swing...
 

Posts:192
Registered: 30/05/01
Re: Force a ToolTip to show itself?  
Aug 4, 2004 7:18 AM (reply 2 of 9)



 
You can force a tooltip display using Ctrl-F1. You can achieve this by adding a FocusAdapter to the JPanel - or whatever you're using.

[code]
FocusAdapter fa = new FocusAdapter()
{
public void focusGained(FocusEvent e)
{
Component c = (Component)e.getSource();
c.dispatchEvent( new KeyEvent (c, KeyEvent.KEY_PRESSED, 0, KeyEvent.CTRL_MASK, KeyEvent.VK_F1) );
}
};
[/code
 

Posts:105
Registered: 6/8/04
Re: Force a ToolTip to show itself?  
Aug 4, 2004 7:36 AM (reply 3 of 9)



 
You can force a tooltip display using Ctrl-F1. You can achieve this by adding a FocusAdapter to the
JPanel - or whatever you're using.

Alright, I just tried that, and it's not working. The ToolTip is set, the FocusAdapter goes off, but no dice. So I tried just manually pushing Ctrl+F1 after setting the ToolTip, and that didn't force it to display. I took off the KeyListener that was added to it, but it still doesn't show up. Should I be using a JToolTip directly? I've just been setting the toolTipText...
 

Posts:14,142
Registered: 99-04-02
Re: Force a ToolTip to show itself?  
Aug 4, 2004 7:43 AM (reply 4 of 9)



 
yeah, what system is this that use Ctrl+F1 to force tooltips? Cuz it ain't Windows.

I'm not sure if there is a way to force it... Instead, what you might want is a popup window... look at javax.swing.PopupManager, putting whatever display component in it and use a mouse listener to track movement to hide it.
 

Posts:4,906
Registered: 23/07/02
Re: Force a ToolTip to show itself?  
Aug 4, 2004 8:58 AM (reply 5 of 9)



 
As a matter of fact, ToolTips display with a popup window anyway.
The other idea I've had is to get the ToolTipUI and call paint on it manually.
 

Posts:105
Registered: 6/8/04
Re: Force a ToolTip to show itself?  
Aug 4, 2004 9:11 AM (reply 6 of 9)



 
Thanks for all the advice. I tried using a Popup, but there was, of course, the annoying "Java applet window" part that I didn't like.

So, basically I just decided to bite the bullet and paint the thing manually onto my JPanel. 'Twas annoying, but meh.
 

Posts:14,142
Registered: 99-04-02
Re: Force a ToolTip to show itself?  
Aug 4, 2004 10:58 AM (reply 7 of 9)



 
the annoying "Java applet window" ...

signed applet will get rid of this. I'm not sure what the deal is with that, but it seems to me that sometimes this doesn't show for popup menus, and sometimes it does. I could never figure it out... except maybe it's a slight JVM version difference that I'm comparing... but I thought I saw it happen on the same PC...
 

Posts:24,517
Registered: 98-02-27
Re: Force a ToolTip to show itself?  
Aug 4, 2004 9:10 PM (reply 8 of 9)



 
You can force a tooltip display using Ctrl-F1. You can achieve this by adding a FocusAdapter to the
JPanel - or whatever you're using.

Alright, I just tried that, and it's not working. The ToolTip is set, the FocusAdapter goes off, but no dice. So I tried just manually pushing Ctrl+F1 after setting the ToolTip, and that didn't force it to display. I took off the KeyListener that was added to it, but it still doesn't show up. Should I be using a JToolTip directly? I've just been setting the toolTipText...

Works fine for me. Since you didn't post any code I don't know what you are doing wrong, but this [url http://forum.java.sun.com/thread.jsp?forum=57&thread=334751]thread[/url] has a simple working demo.

yeah, what system is this that use Ctrl+F1 to force tooltips? Cuz it ain't Windows.

Don't know if this is a Swing convention but according to the Java documentation this is part of the Windows Look and Feel:

a) go to the API for JTextField
b) search for - "For the keyboard keys used by this component in the standard Look and Feel (L&F) renditions, see the JTextField key assignments."
- and click on the link for JTextField key assignments
c) click on the "key-windows" link
d) search for "jtooltip"
e) Ctrl+F1 is listed
 

Posts:14,142
Registered: 99-04-02
Re: Force a ToolTip to show itself?  
Aug 5, 2004 8:43 AM (reply 9 of 9)



 
doesn't work on my Win2K, Java 1.4.2 setup... or on any other Windows app... dunno... maybe it's only an XP thing?
 
This topic has 9 replies on 1 page.