Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

events for jlist

Thread view: 
rmacnak@gmail.com - 20 Mar 2006 01:02 GMT
I have a JList of objects, I know how to get an event of an item is
selected, but how do i receive an event if an item is double clicked?

thanks in advance
Kurt M Peters - 20 Mar 2006 01:47 GMT
Try something like this:
       jListFiles.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt){
         JList list = (JList)evt.getSource();
         if (evt.getClickCount()==2) goButtonClicked(evt);
        }
       });
>I have a JList of objects, I know how to get an event of an item is
> selected, but how do i receive an event if an item is double clicked?
>
> thanks in advance
Roedy Green - 20 Mar 2006 02:31 GMT
>I have a JList of objects, I know how to get an event of an item is
>selected, but how do i receive an event if an item is double clicked?

quoting from the 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);
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.