Java JList Add Remove addDoubleClickEvent(JList list)

Here you can find the source of addDoubleClickEvent(JList list)

Description

add Double Click Event

License

Open Source License

Declaration

public static void addDoubleClickEvent(JList list) 

Method Source Code


//package com.java2s;
/*/*  w  ww  .  j  a  v  a  2 s . c  o  m*/
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2003-2008, Open Source Geospatial Foundation (OSGeo)
 *        
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */

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

import javax.swing.JList;

import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class Main {
    public static void addDoubleClickEvent(JList list) {
        list.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                JList source = (JList) e.getSource();
                if (e.getClickCount() == 2) {
                    ListSelectionListener[] listeners = source.getListSelectionListeners();
                    for (int i = 0; i < listeners.length; i++) {
                        listeners[i].valueChanged(new ListSelectionEvent(source, source.getSelectedIndex(),
                                source.getSelectedIndex(), false));
                    }
                }
            }
        });
    }
}

Related

  1. addItemJList(javax.swing.JList jlist, String item)
  2. addToList(JList list, Object object)
  3. fillList(Collection anList, JList anJList)
  4. fillList(JList aListComponent, String theList, boolean removeQuotes)