e783. 监听对JList中项双击和三击

 // 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
            }
        }
    });
Related Examples
原文地址:https://www.cnblogs.com/borter/p/9596136.html