Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > events for jlist

Reply
Thread Tools

events for jlist

 
 
rmacnak@gmail.com
Guest
Posts: n/a
 
      03-20-2006
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

 
Reply With Quote
 
 
 
 
Kurt M Peters
Guest
Posts: n/a
 
      03-20-2006
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);
}
});
<> wrote in message
news: ups.com...
>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
>



 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      03-20-2006
On 19 Mar 2006 16:02:14 -0800, "" <>
wrote, quoted or indirectly quoted someone who said :

>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);
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Events Events Events Please Help Chris ASP .Net Web Controls 0 08-30-2005 08:21 PM
JList Problems Tom Java 1 07-30-2003 03:15 PM
JList problem. Tom Java 1 07-30-2003 12:53 PM
JList question - how to fire a change event when nothing has changed? Sam Java 0 07-17-2003 10:40 PM
JList question Passero Java 1 06-28-2003 12:17 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57