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

前端 未结 4 1175
不思量自难忘°
不思量自难忘° 2020-12-29 21:39

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 onl

4条回答
  •  北海茫月
    2020-12-29 21:56

    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);
      }
    });
    

提交回复
热议问题