?
Solved

DoubleClick event in JAVA

Posted on 2003-02-22
5
Medium Priority
?
926 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

765 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