2011-03-14 61 views
1

当我在屏幕按钮附近有按钮时,工具提示出现在鼠标下方。点击会使工具提示消失,而不是点击按钮。工具提示窃取鼠标事件

Tooltip Example

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

任何想法如何确保按钮接收在这种情况下,点击?

回答

0

这只会发生,如果你停止你的鼠标按钮,等待工具提示,然后移动你的鼠标,然后点击工具提示。如果在出现工具提示之前点击该按钮,或者如果您在点击/之前没有将鼠标移至工具提示,用户应该没问题。

我相信这正是一个工具提示应该如何工作,你点击它来解雇它。如果这是造成问题,我建议的三个选项之一:

  1. 将延迟提示要长:ToolTipManager.sharedInstance().setInitialDelay()
  2. 不显示在所有
  3. 一个提示写自己的鼠标移动侦听器而不是将工具提示显示在GUI的侧面或另一部分。
相关问题