Detecting Double and Triple Clicks - Java Swing

Java examples for Swing:Mouse Event

Description

Detecting Double and Triple Clicks

Demo Code


import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JTextField;

public class Main {
  public void m() throws Exception {
    JTextField component = null;//from   w  w  w.jav  a  2 s . c o m
    component.addMouseListener(new MyMouseListener());
  }
}

class MyMouseListener extends MouseAdapter {
  public void mouseClicked(MouseEvent evt) {
    if (evt.getClickCount() == 3) {
      // triple-click
    } else if (evt.getClickCount() == 2) {
      // double-click
    }
  }
}

Related Tutorials