Mouse event with double click in java

drew picture drew · Dec 7, 2011 · Viewed 45.5k times · Source

By default MouseClicked event starts with one click. I have one in a JTextPane but I want to start with double click. Is it possible?

Answer

Johnny Rocket picture Johnny Rocket · Dec 7, 2011

I believe you can extract the click count from the MouseEvent (assuming its called e)

Try this

if (e.getClickCount() == 2 && !e.isConsumed()) {
     e.consume();
     //handle double click event.
}