title: Populate combo box with table values
body: <p><strong>EDIT(NEW):</strong> </p>
  
  <p>Still haven't figured out how to populate the <code>cboxCustomers</code>. I've been at it for the past day or two, but without luck.</p>
  
  <p>In case anyone can help: <a href="http://pastebin.com/e5wibRYw" rel="nofollow">http://pastebin.com/e5wibRYw</a></p>
  
  <p>I went from <code>cats</code> to <code>customers</code>, btw. </p>
  
  <p>I tried <code>Mr. Xymon's</code> approach, but didn't implement it correctly since it didn't work.</p>
  
  <p>Whatever event I used to handle the population I always got <code>NullPointerException</code> for whatever control/event I was trying to use.</p>
  
  <p><strong>OLD:</strong></p>
  
  <p><strike>There's a <code>JForm</code>. On it, there's a single combo box. Also have a single table with cats - <code>cats</code>. Each cat has <code>id</code>, and <code>catName</code>.  </strike></p>
  
  <p>What I wanted to do was when I click on the combo box, thus expanding it, populate it with all <code>id</code> of cats that are found in <code>cats</code> table.</p>
  
  <p><strong>SLOVED. Asnwer below.</strong>
  Unfortunately I receive numerous <code>unreported exception java.sql.SQLException</code> from the lines I've indicated with <code>&gt;</code>:</p>
  
  <pre><code>private void cboxCatsMouseClicked(java.awt.event.MouseEvent evt) {
          // TODO add your handling code here:
          // create an array list to be filled with cat's ids
          ArrayList&lt;String&gt; cats = new ArrayList&lt;String&gt;();
          String query = "SELECT id FROM cats ORDER BY id";
          &gt;java.sql.PreparedStatement stm = connection.prepareStatement(query);
  
          &gt;ResultSet rs = stm.executeQuery(query);
  
          &gt;while(rs.next()){
              &gt;String cat = rs.getString("id");
              // add cat's ids tp the array list
              cats.add(cat);
          }
  
          &gt;rs.close();
  
          // populate the combo box
          DefaultComboBoxModel model = new DefaultComboBoxModel(cats.toArray());
          cboxCats.setModel(model);
      }
  </code></pre>
  
  <p><strong>OLD ANSWER:</strong></p>
  
  <p>I think I fixed it. I just had to wrap all of the highlighted lines of code together into one big <code>try-catch</code> statement that would catch <code>SQLException</code>. Problem is - the combo box doesn't get populated with <code>id</code> values when I expand it. Why is that? Am I using the wrong event?</p>