强制显示Java工具提示 [英] Force a Java Tooltip to Appear

查看:54
本文介绍了强制显示Java工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个 JTextField (或与此有关的任何 JComponent ),如何迫使该组件的指定工具提示出现而用户没有任何直接输入事件?换句话说,为什么没有 JComponent.setTooltipVisible(boolean)?

Given a JTextField (or any JComponent for that matter), how would one go about forcing that component's designated tooltip to appear, without any direct input event from the user? In other words, why is there no JComponent.setTooltipVisible(boolean)?

推荐答案

我发现的唯一方法(除了创建自己的工具提示"窗口外)是重点突出CTRL + F1击键:

The only way (besides creating your own Tooltip window) I've found is to emmulate the CTRL+F1 keystroke on focus:

new FocusAdapter()
{
    @Override
    public void focusGained(FocusEvent e)
    {
        try
        {
            KeyEvent ke = new KeyEvent(e.getComponent(), KeyEvent.KEY_PRESSED,
                    System.currentTimeMillis(), InputEvent.CTRL_MASK,
                    KeyEvent.VK_F1, KeyEvent.CHAR_UNDEFINED);
            e.getComponent().dispatchEvent(ke);
        }
        catch (Throwable e1)
        {e1.printStackTrace();}
    }
}

不幸的是,只要将鼠标移到组件外部(在组件外部)或经过一段时间(请参阅 ToolTipManager.setDismissDelay ),工具提示就会消失.

Unfortunately, the tooltip will disappear as soon as you move your mouse (outside of the component) or after a delay (see ToolTipManager.setDismissDelay).

这篇关于强制显示Java工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆