Detecting Double and Triple Clicks on an Item in a JList Component

// Create a list String[] items = {"A", "B", "C", "D"}; JList list = new JList(items); // Add a listener for mouse clicks list.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { JList list = (JList)evt.getSource(); if (evt.getClickCount() == 2) { // Double-click // Get item index int index = list.locationToIndex(evt.getPoint()); } else if (evt.getClickCount() == 3) { // Triple-click // Get item index int index = list.locationToIndex(evt.getPoint()); // Note that this list will receive a double-click event before this triple-click event } } });

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.