The problem is that Object#wait
is waiting(rather than sleeping) to be notified but this is not happening. Instead the timeout causing an InterruptedException
bypassing the call to clearSelection
.
Don't use raw Threads
in Swing
applications. Instead use a Swing Timer
which was designed to interact with Swing components.
if (!todoList.isSelectionEmpty()) {
Timer timer = new Timer(400, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
todoList.clearSelection();
}
});
timer.setRepeats(false);
timer.start();
}