title: Use of JComboBox and DefaultComboBoxModel in JAVA
body: <p>I was tasked to create a panel with two comboboxes, the second combobox's item should rely on what was selected on the first combobox. Below is the code snippet of what I've done. I apologize if this was poorly written. It is my first time to do such things.</p>
  
  <pre><code>    // Sets up comboSearch and comboFor
      String[] searchList = {"Class", "Member", "Procedure"};
      final String[] forClassList = {"Parent", "Child", "Procedures", "Members", "All"};
      final JComboBox comboSearch = new JComboBox(searchList);
      final DefaultComboBoxModel&lt;String&gt; model = new DefaultComboBoxModel(forClassList);
      final JComboBox comboFor = new JComboBox(model);
      searchSelect = (String) comboSearch.getSelectedItem();
      comboSearch.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              searchSelect = (String) comboSearch.getSelectedItem();
              System.out.println(searchSelect);
              switch (searchSelect) {
                  case "Class":
                      model.removeAllElements();
                      model.addElement("Parent");
                      model.addElement("Child");
                      model.addElement("Procedures");
                      model.addElement("Members");
                      model.addElement("All");
                      break;
                  case "Member":
                      model.removeAllElements();
                      model.addElement("Owner");
                      break;
                  case "Procedure":
                      model.removeAllElements();
                      model.addElement("Owner");
                      model.addElement("Owner Parent");
                      model.addElement("Owner Users");
                      break;
              }
          }
      });
      comboFor.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              forSelect = (String) comboFor.getSelectedItem();
              System.out.println(forSelect);
          }
      });
  </code></pre>
  
  <p>The problem is that whenever I try to execute this, when I select from the first combobox, <code>null</code> is being printed before the actual value. I think this is because of the <code>model.removeAllElements();</code> part of the code.</p>
  
  <p>Below is the screenshot of the output.</p>
  
  <p><a href="https://i.stack.imgur.com/xNt3G.jpg" rel="nofollow noreferrer">output</a></p>
  
  <p>Any suggestions to optimize this one is very much appreciated and welcomed.</p>
  
  <p>Thanks,</p>