Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Double Click a JList item

Posted on 2006-04-02
4
Medium Priority
?
1,314 Views
Last Modified: 2012-06-27
Hi folks,

I want to double click a JList item to open a new window. How should I do that?

Specifically, I have a JList which its data is from a collection of images (which contains info like image size, file name, etc.). I want to double click a list item, then a new window opens, so that I can display the full view of the image in the new window.

Which listener shall I use?

Thanks
0
Comment
Question by:tiger0516
  • 2
  • 2
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16356489
A MouseListener
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 1000 total points
ID: 16356491
0
 
LVL 92

Accepted Solution

by:
objects earned 1000 total points
ID: 16356509
from the JList javadoc:

 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);
 
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

564 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