Link to home
Start Free TrialLog in
Avatar of mrpatel
mrpatel

asked on

DoubleClick event in JAVA

Hi all,
   I am new in Java Graphincs. I have a JList of strings. Now when a user Double clicks on one of the items in list, I need to perform some action. How do I Create the DoubleClick Event?

Thanks,
-Mehul
Avatar of sfotex
sfotex

http://java.sun.com/docs/books/tutorial/uiswing/events/mouselistener.html

a dblclick would be
press
release
press
release

You prpbally want to time the clicks, so you can tell
that it's an actuall dblclick,
vs. click ..wait ten minutes... click
ASKER CERTIFIED SOLUTION
Avatar of raffael
raffael

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The following is from the 1.4.1 API documentation for JList:

JList doesn't provide any special support for handling double or triple (or N) mouse clicks however it's easy to handle them using a MouseListener. Use the JList method locationToIndex() to determine what cell was clicked. For example:

 final JList list = new JList(dataModel);
 MouseListener mouseListener = new MouseAdapter() {
     public void mouseClicked(MouseEvent e) {
         if (e.getClickCount() == 2) {
             int index = list.locationToIndex(e.getPoint());
             System.out.println("Double clicked on Item " + index);
          }
     }
 };
 list.addMouseListener(mouseListener);

Note that in this example the dataList is final because it's referred to by the anonymous MouseListener class.
mrpatel:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.