can anyone think of a good way to ignore the single click that comes with a double-click in Java ?
I\'m looking to have different behaviors for each such that:
An alternative solution:
I figured out this before I found the solution in this question. The idea is the same, use a timer, although more complicated :).
Use SwingWorker
:
class BackgroundClickHandler extends SwingWorker {
@Override
protected Integer doInBackground() throws Exception {
Thread.sleep(200);
// Do what you want with single click
return 0;
}
}
In mouseClicked()
method you can do something like this:
if (event.getClickCount() == 1) {
// We create a new instance everytime since
// the execute() method is designed to be executed once
clickHandler = new BackgroundClickHandler();
try {
clickHandler.execute();
} catch(Exception e) {
writer.println("Here!");
}
}
if (event.getClickCount() == 2) {
clickHandler.cancel(true);
//Do what you want with double click
}
I hope it be useful.