I want to set setDissmissDelay() method multiple times, but I could not set it for a specific value again and again. I also tried to use an infinite loop, and tried to override (ToolTipManager Constructor is on default modifier).
I know for sure the code is working properly as I can see it’s printing the e.getsource() in console. I was trying to solve this issue asked by someone (This Question) and while solving that I became stumped at this point. What is the reason behind that? And if I can set the value how can it be? Is there any other way to achieve this?
Here is my code snippet:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.*;
public class Hello {
static JButton button;
private static void createAndShowGUI() {
JFrame frame = new JFrame("HelloWorldSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
button = new JButton("Hello World");
button.setToolTipText("Its a tool tip Experiment!");
frame.getContentPane().add(button);
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
if (e.getSource() == button) {
ActionListener tt = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ToolTipManager.sharedInstance().setDismissDelay(
1000);
System.out.println(e.getSource());
}
};
new Timer(100, tt).start();
}
}
});
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
Please guide me through this.
Calling
setDismissDelay()is a global setting to indicate how long should a Tooltip remain on the display before it is removed. It does not reset the time until when the current tooltip is removed. As suggested in your linked question setting the dismiss delay, once and for all, toInteger.MAX_VALUEshould do the trick.