title: Double click event on JList element
body: <p>I've got a problem, and I can't find an answer by myself.
  I'm making a simple chat in java, and I populated a JList with names. When a name is double-clicked, that name needs to be passed as an argument to another frame (as a recipient name). But, double click does not work</p>
  
  <p>I've got a main class InstantMessageFrame, in which a JList named friends is initialized and filled with an array of strings.</p>
  
  <pre><code>private JList&lt;String&gt; friends;
  String names[] = { "Ana", "Banana", "Cikla", "Doris", "Ema", "Mirna","Matea","Veronika","Vera","Marta","Mirta","Davor","Marko","Matko","Kloki" };
  JList&lt;String&gt; friends = new JList&lt;String&gt;(names);
  </code></pre>
  
  <p>Also,I added a listener to my JList</p>
  
  <pre><code>DisplayMessageDialog dmd = new DisplayMessageDialog();
  friends.addMouseListener(dmd);
  </code></pre>
  
  <p>This is my DisplayMessageDialog class which checks if there was a double click. If there is a double click, a new Frame should appear. None of the lines in the first "if" statement executes (one with the e.getClickCount())</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  public class DisplayMessageDialog extends MouseAdapter
  {
      public void mouseClicked(MouseEvent e)
      {
          JList theList = (JList) e.getSource();
          if (e.getClickCount() == 2) 
          {
              int index = theList.locationToIndex(e.getPoint());
              if (index &gt;= 0) 
              {
                  Object o = theList.getModel().getElementAt(index);
                  InstantMessageDialog imd = new InstantMessageDialog(null, o.toString());
                  imd.setVisible(true);
              System.out.println("Double-clicked on: " + o.toString());
              }
          }
      }
  }
  </code></pre>
  
  <p>This is how it should look like:</p>
  
  <p><a href="http://i.stack.imgur.com/Bex5U.png" rel="nofollow">http://i.stack.imgur.com/Bex5U.png</a></p>
  
  <p>And when double clicked,a new frame should appear (in code "InstantMessageDialog" object)</p>
  
  <p><a href="http://i.stack.imgur.com/yjvW6.png" rel="nofollow">http://i.stack.imgur.com/yjvW6.png</a></p>
  
  <p>And it should look like this.</p>