title: Adding JComboBox to a JTable cell
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2059229/how-to-add-a-jcombobox-to-a-jtable-cell">How to add a JComboBox to a JTable cell?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm finding it difficult to add <code>JComboBox</code> to one of the cells of a <code>JTable</code>, I tried the code below but it's not working..</p>
  
  <p><strong>How can I add jcombobox to a particular cell?</strong></p>
  
  <p>On pressing <code>enter</code> a new <code>jcombobox</code> should be added automatically to the desired column.</p>
  
  <pre><code>jTable1 = new javax.swing.JTable();
  mod=new DefaultTableModel();
  mod.addColumn("No");
  mod.addColumn("Item ID");
  mod.addColumn("Units");
  mod.addColumn("Amount");
  mod.addColumn("UOM");
  mod.addColumn("Delivery Date");
  mod.addColumn("Total Amount");
  mod.addColumn("Notes");
  mod.addColumn("Received");
  mod.addRow(new Object [][] {
          {1, null, null, null, null, null, null, null, null}
      });
  jTable1.setModel(mod);
  jTable1.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(generateBox()));
  jTable1.setColumnSelectionAllowed(true);
  
  
  Code to generate ComboBox
  
  private JComboBox generateBox()
   {
       JComboBox bx=null;
       Connection con=CPool.getConnection();
       try
       {
           Statement st=con.createStatement();
           String query="select distinct inid from inventory where company_code="+"'"+ims.MainWindow.cc+"'";
           ResultSet rs=st.executeQuery(query);
           bx=new JComboBox();
           while(rs.next()){
               bx.addItem(rs.getString(1));
           }
           CPool.closeConnection(con);
           CPool.closeStatement(st);
           CPool.closeResultSet(rs);
       }catch(Exception x)
       {
           System.out.println(x.getMessage());
       }
               return bx;
  
   }
  </code></pre>