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:
ToolTipManager.sharedInstance().setInitialDelay()