?
Solved

DoubleClick event in JAVA

Posted on 2003-02-22
5
Medium Priority
?
941 Views
Last Modified: 2011-09-20
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
0
Comment
Question by:mrpatel
4 Comments
 
LVL 2

Expert Comment

by:sfotex
ID: 8001894
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
0
 

Accepted Solution

by:
raffael earned 100 total points
ID: 8002179
@sfotex: Things are much easier!

Just give a try to [MouseEvent].getClickCount(). It returns two in case of a double-click.

Best regards, Raffael Vogler
0
 
LVL 9

Expert Comment

by:yongsing
ID: 8002613
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.
0
 

Expert Comment

by:CleanupPing
ID: 9059139
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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Don’ts and Dos are two important end products of software testing basics that a tester needs to regard. This article attempts to explain the principles of both.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month8 days, 15 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question