Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mouse event with double click in java

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?

like image 884
drew Avatar asked Dec 07 '11 01:12

drew


People also ask

What is the difference between clicking and double-clicking?

Typically, a single click initiates a user interface action and a double-click extends the action. For example, one click usually selects an item, and a double-click edits the selected item.

What happens on double-clicking?

A double-click is the act of pressing a computer mouse button twice quickly without moving the mouse. Double-clicking allows two different actions to be associated with the same mouse button.


2 Answers

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.
}
like image 162
Johnny Rocket Avatar answered Sep 23 '22 10:09

Johnny Rocket


I don't think there will be a solution to this, since Java can run on non-pc devices.

Most portable devices don't support double-click.

You may keep track of the moment of each mouse click and fire your own "double-click" event. But I don't think this is a good idea.

like image 31
xiesusu Avatar answered Sep 19 '22 10:09

xiesusu