Disable Tooltip Delay In Java Swing


I am not really sure if there is a concrete way to do this. In my case, what I did was create a dirty hack to prolong a tooltip’s visible delay by making use of the ToolTipManager setDismissDelay() method.

I figure nobody would look at a tooltip for a whole 10 minutes so that it what I set as default value. By setting the setDismissDelay() method to 10 minutes of equivalent milliseconds in the component’s mouseEntered event, the tooltip will always show itself until the mouse cursor is off the component’s area when mouseExited is invoked.

As I said, it may not be the accurate way to stop the delay but it works! ;)

1
2
3
4
5
6
7
8
9
10
11
12
13
label.addMouseListener(new MouseAdapter() {
    final int defaultDismissTimeout = ToolTipManager.sharedInstance().getDismissDelay();
    final int dismissDelayMinutes = (int) TimeUnit.MINUTES.toMillis(10); // 10 minutes
    @Override
    public void mouseEntered(MouseEvent me) {
        ToolTipManager.sharedInstance().setDismissDelay(dismissDelayMinutes);
    }
 
    @Override
    public void mouseExited(MouseEvent me) {
        ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);
    }
});

Found this post useful? Buy me a cup of coffee or help support the sponsors on the right.

Related Posts with Thumbnails