title: Java swing popup menu and jlist
body: <p>here is my problem:
  I have a jList and a popup menu. When I right click the jList, the popup menu shows. The problem is that the jList item which the mouse is pointing at won't select.
  And I want it to do that. When I point my cursor at an item in the list and press the right button, I want two things to happen. Select the item on which I clicked and show the popup menu.</p>
  
  <p>I tried this:</p>
  
  <pre><code>jLists.addMouseListener(new MouseAdapter() {
  
       @Override
       public void mousePressed(MouseEvent e) {
              jList.setSelectedIndex(jList.locationToIndex(e.getPoint()));
       }
  });
  
  jList.setComponentPopupMenu(jPopupMenu);
  </code></pre>
  
  <p>But it only shows the popup menu.
  If I delete this line:</p>
  
  <pre><code>jList.setComponentPopupMenu(jPopupMenu);
  </code></pre>
  
  <p>then the right-click select works (but the popup menu doesn't show).</p>
  
  <p>So, what do you think is the best way to make these two functions (both) work ?</p>
  
  <p>Thanks and sorry for my english.</p>