title: multiple linked combobox in java
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3191837/dynamic-jcomboboxes">Dynamic JComboBoxes</a>  </p>
  </blockquote>
  
  
  
  <p>I am a newbie in java program.
  I have this problem with my program about comboboxes.
  I have 3 combobox (cbxType, cbxItem, and cbxColor). I want that the item list in the second combobox (cbxItem) is changed based on the first one (type), and then the third combobox's(cbxColor) item list changed based on the selected item in the second one (cbxItem).
  i've been trying to solve this problem by my own code, the second combobox work fine when the first one changed, but then the third combobox won't show any item after i change.
  here is my code.
  thanks for your help guys and sorry for my bad english..</p>
  
  <pre><code>    private void viewCbxType(){
      String sql;
  
  
  try {
      sql ="Select distinct productItem from Product ";
      if(cbxType.getSelectedItem() != "&lt;&lt;Product Type&gt;&gt;"){
  
          String prType = cbxType.getSelectedItem().toString();
  
          sql ="Select distinct productItem from Product WHERE productType='" +prType+"'";
  
  
  
              cbxItem.removeAllItem();
              cbxItem.setSelectedIndex(0);
          }
      }
  
  
      PreparedStatement st = conn.prepareStatement(sql);
      ResultSet rs =st.executeQuery();
  
  
  
      while (rs.next()) {
          String prItem = rs.getString("productItem");
  
          cbxItem.addItem(prItem);
  
      }
  }catch (SQLException se) {}
  }
  </code></pre>
  
  <p>I call that method at actionPerformed for my first combobox and make similiar to the second</p>