Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the Tooltip Delay Time for a Particular Component in Java Swing

I'm trying to set tooltips on a JEditorPane. The method which I use to determine what tooltip text to show is fairly CPU intensive - and so I would like to only show it after the mouse has stopped for a short amount of time - say 1 second.

I know I can use ToolTipManager.sharedInstance().setInitialDelay(), however this will set the delay time for tooltips on all swing components at once and I don't want this.

like image 872
Scottm Avatar asked Jul 27 '09 19:07

Scottm


People also ask

How long should a tooltip delay be?

Wait 0.3–0.5 seconds. If cursor remains stopped within target area, display corresponding hidden content within 0.1 seconds. Keep displaying the exposed content element until the cursor has left the triggering target area or the exposed content for longer than 0.5 seconds.

Which method is used to add tooltip text to almost all components of Java Swing?

We can add tooltip text to almost all the components of Java Swing by using the following method setToolTipText(String s). This method sets the tooltip of the component to the specified string s. When the cursor enters the boundary of that component a popup appears and text is displayed.

Which method is used to set the tool tip text?

Creating a tool tip for any JComponent object is easy. Use the setToolTipText method to set up a tool tip for the component.

How do I enable Tooltips in Java?

How to Turn On Advanced Tooltips. The easiest way to turn on Advanced Tooltips in Minecraft is to press F3+H at the same time.


1 Answers

If what you want is to make the tooltip dismiss delay much longer for a specific component, then this is a nice hack:

(kudos to tech at http://tech.chitgoks.com/2010/05/31/disable-tooltip-delay-in-java-swing/)

private final int defaultDismissTimeout = ToolTipManager.sharedInstance().getDismissDelay();  addMouseListener(new MouseAdapter() {    public void mouseEntered(MouseEvent me) {     ToolTipManager.sharedInstance().setDismissDelay(60000);   }    public void mouseExited(MouseEvent me) {     ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);   } }); 
like image 185
Noel Grandin Avatar answered Sep 24 '22 07:09

Noel Grandin