Force a Java Tooltip to Appear

后端 未结 5 1047
慢半拍i
慢半拍i 2021-01-07 22:51

Given a JTextField (or any JComponent for that matter), how would one go about forcing that component\'s designated tooltip to appear, without any

5条回答
  •  梦谈多话
    2021-01-07 23:07

    For me works the similar version stated above (instead of Timer I used SwingUtilities and invokeLater approach):

    private void showTooltip(Component component)
    {
        final ToolTipManager ttm = ToolTipManager.sharedInstance();
        final int oldDelay = ttm.getInitialDelay();
        ttm.setInitialDelay(0);
        ttm.mouseMoved(new MouseEvent(component, 0, 0, 0,
                0, 0, // X-Y of the mouse for the tool tip
                0, false));
        SwingUtilities.invokeLater(new Runnable()
        {
            @Override
            public void run() 
            {
                ttm.setInitialDelay(oldDelay);
            }
        });
    }
    

提交回复
热议问题