Given the single threaded nature of the Swing API and the fact that the API is not thread safe, I'd recommend using a Swing Timer
to inject a small delay between the event and your operation, for example...
Timer timer = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
//...
}
});
timer.setRepeats(false); // So you are notified only once per mouseEnter event
jl.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent me) {
timer.restart();
}
});
This example will delay the calling of the ActionListener
by 1 second every time the mouse triggers the mouseEntered
event. Note though, if the user exits and enters the label before the delay expires, it will be reset back to the start.
If you want some event to trigger 1 second after ANY mouseEnter
event, then you could simply create a new Swing Timer
on each mouseEnter
event instead.
Take a look at Concurrency in Swing and How to use Swing Timers for more details