events for jlist

Discussion in 'Java' started by rmacnak@gmail.com, Mar 20, 2006.

  1. Guest

    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
     
    , Mar 20, 2006
    #1
    1. Advertising

  2. 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:...
    >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, Mar 20, 2006
    #2
    1. Advertising

  3. Roedy Green Guest

    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.
     
    Roedy Green, Mar 20, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Passero

    JList question

    Passero, Jun 28, 2003, in forum: Java
    Replies:
    1
    Views:
    1,112
    Stephan Friedrichs
    Jun 28, 2003
  2. Sam
    Replies:
    0
    Views:
    902
  3. Tom

    JList problem.

    Tom, Jul 30, 2003, in forum: Java
    Replies:
    1
    Views:
    717
  4. Tom

    JList Problems

    Tom, Jul 30, 2003, in forum: Java
    Replies:
    1
    Views:
    452
    Dave Roberts
    Jul 30, 2003
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    366
    Chris
    Aug 30, 2005
Loading...

Share This Page