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?
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.
}
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.
private void jEditorPane3MouseClicked(java.awt.event.MouseEvent evt) {
if (evt.getClickCount() == 2 && !evt.isConsumed()) {
evt.consume();
System.out.println("Double Click");
}
}
您可以覆盖mousePressed()或mouseReleased()方法并询问是否e.getClickCount()== 2,我建议使用mousePressed()或mouseReleased()而不是mouseClicked()方法,因为使用这些方法会给用户更多时间执行点击。
You can compute the time lapsed between consecutive clicks. Compare it with a threshold value and decide yourself whether it is a double click or not.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.