title: Retrieving array data for JList items
body: <p>I have an (access) database table which contains data I would like to populate into a list in my java program. The table consists of multiple columms (id, name, etc)</p>
  
  <p>What I would like is a JList listing all the name(s) and then when an item from the list has been double clicked I would like the id number for that item to be inserted into another table.</p>
  
  <p>I have already implemented the list and populated it with the records from the db table (name column). What I'm having trouble with is when the user double-clicks on the item, how do I can I get get the ID for that video? The database call which populates the list selects multiple columns and puts them all into an array, not quite sure how I can link that list item to the array.</p>
  
  <p>Here is what I got so far...</p>
  
  <p>The java class</p>
  
  <pre><code>  ArrayList list = new ArrayList();
    ArrayList video = new ArrayList();
    list = VideoData.getVideoList();
  
    JList videolist = new JList();;  
    Vector data = new Vector();;  
  
    for (int i=0; i &lt; list.size(); i++) {
             video = (ArrayList) list.get(i);
             data.addElement(video.get(3));
         }
  
    videolist.setListData(data);
    videolist.setSelectedIndex(0);
    videolist.addMouseListener(new ActionJList(videolist));
    videolist.setFixedCellWidth(300);
    add(new JScrollPane(videolist));
  </code></pre>
  
  <p>What getVideoList() contains</p>
  
  <pre><code>ArrayList list = new ArrayList();
  
  try {
      ResultSet res = stmt.executeQuery("SELECT * FROM Items ORDER BY VidID ASC");
      while (res.next()) { // there is a result
        ArrayList sub = new ArrayList();
        sub.add(res.getString("VidID"));;
        sub.add(res.getString("Name"));
        sub.add(res.getString("Writer"));
         // add sub array  to list
        list.add(sub); 
      }
  } catch (Exception e) {
      System.out.println(e);
      return null;
  }
  
  return list;
  </code></pre>
  
  <p>The current doulbe-click function is the following (which I found on the net)</p>
  
  <pre><code>  public void mouseClicked(MouseEvent e){     
     if(e.getClickCount() == 2){ // double click
       int index = list.locationToIndex(e.getPoint());
       ListModel dlm = list.getModel();
       Object item = dlm.getElementAt(index);;
       list.ensureIndexIsVisible(index);
       System.out.println("Double clicked on " + item);
       }
     }
  </code></pre>
  
  <p>.. From this <em>item</em> only tells me what is listed inside the JList cell, What I need to to be able to do is get the other array data for that selected item.</p>