工具提示窃取鼠标事件 [英] Tooltip stealing mouse events

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

问题描述

当我在屏幕按钮附近有按钮时,工具提示出现在鼠标下方.然后,单击将使工具提示消失,而不是单击按钮.

When I have buttons near the button of the screen, the tooltip appears underneath the mouse. Clicking will then make the tooltip disappear, instead of clicking the button.

 public static void main(String[] args) {
    JFrame frame = new JFrame("Test");
    JButton button = new JButton("Test");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("action performed");
        }
    });
    button.setToolTipText("Sample tooltip text");
    frame.add(button);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    frame.pack();
}

您知道在这种情况下如何确保按钮获得点击吗?

Any idea how to ensure that the button receives the click in this case?

推荐答案

仅当您将鼠标停在按钮上,等待工具提示,然后移动鼠标并单击工具提示时,才会发生这种情况.如果您在工具提示出现之前单击按钮,或者在单击之前不将鼠标移至工具提示,则您/您的用户应该没问题.

This will only happen if you stop your mouse on the button, wait for a tooltip, then move your mouse and click on the tooltip. If you click on the button before the tooltip appears or if you don't move the mouse to the tooltip before you click you/your users should be fine.

我相信这正是工具提示的工作方式,您单击它即可将其关闭.如果这引起问题,我建议使用以下三个选项之一:

I believe this is exactly how a tooltip should work, you click on it to dismiss it. If this is causing issues, I would suggest one of three options:

  1. 设置工具提示的延迟时间更长:ToolTipManager.sharedInstance().setInitialDelay()
  2. 完全不显示工具提示
  3. 编写自己的鼠标动作侦听器,而不是在GUI的侧面或另一部分显示工具提示.

这篇关于工具提示窃取鼠标事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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