title: How to add items to a combobox that refresh after selection?
body: <p>I am creating a Java Swing (WindowBuilder) application for my team, but due to my lack of knowledge I keep hitting a wall. What I am trying to achieve is auto-population of items inside a ComboBox after a user has clicked on a previous selection, and so on. The way the code currently works is that when a user fills in information for a specific HTTP GET request, they are greeted with a ComboBox pre-filled with formatted information from that request in which they can select one of the items from the list and once they do it kicks off another HTTP GET request using details from the previous request, and so on.</p>
  
  <p>I do not think my approach is correct as I keep stumbling upon a "MalformedURL" exception whenever I retrieve a JSON HTTP "GET" response. I have debugged the code and found that it skips over all the ActionListeners I have for that specific ComboBox. Currently, I am using the mentioned code multiple times throughout the code to simulate the <code>comboBox.GetSelectedItem()</code> event every-time a user selects the value from the drop-down list. I believe the code keeps skipping the ActionListener maybe due to the way it's implemented multiple times right on top of the other, thus always listening for a single particular event? </p>
  
  <pre><code>comboBox.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
              for (int i = 0; i &lt; list.size(); i++) {
                  String name = list.get(i);
                  if (comboBox.getSelectedItem().toString().contains(name.substring(0, name.lastIndexOf(",")))) {
                      selectedViewURL = name.substring(name.lastIndexOf(",") + 1);
                      break;
                  }
              }
              try {
                  String getNodeViewJson = Get(selectedViewURL + "/api/json?pretty=true");
                  list.clear();
                  comboBox.removeAll();
                  JSONObject nodeViewJsonObject = new JSONObject(getNodeViewJson);
                  JSONArray jobsArrayNodeView = nodeViewJsonObject.getJSONArray("jobs");
                  if (jobsArrayNodeView != null) {
                      for (int i = 0; i &lt; jobsArrayNodeView.length(); i++) {
                          JSONObject jsonObject = jobsArrayNodeView.getJSONObject(i);
                          String jenkinsClass = jsonObject.getString("_class");
                          String jenkinsName = jsonObject.getString("name");
                          String jenkinsURL = jsonObject.getString("url");
                          if (jenkinsClass.contains("com.cloudbees.hudson.plugins.folder.Folder")) {
                              comboBox.addItem(jenkinsName);
                              list.add(jenkinsName + "," + jenkinsURL);
                          }
                      }
                  }
              } catch (Exception ex) {
                  ex.printStackTrace();
              }
          }
      });
  </code></pre>
  
  <p>I am expecting the ComboBox to populate values upon the selection of a pre-existing value in the ComboBox list, and ultimately following that same structure until the end. Any help for this would be highly appreciated, thank you.</p>
  
  <p>This is the repeated error that shows right after it populates the ComboBox with initial values from the HTTP GET request: </p>
  
  <pre><code>java.net.MalformedURLException: no protocol: /api/json?pretty=true
  at java.net.URL.&lt;init&gt;(Unknown Source)
  at java.net.URL.&lt;init&gt;(Unknown Source)
  at java.net.URL.&lt;init&gt;(Unknown Source)
  at impl.Logic.Get(Logic.java:141)
  at net.java.maven_jenkins_tool.JenkinsRemoteRegressionTool.JenkinsTool$8.actionPerformed(JenkinsTool.java:851)
  at javax.swing.JComboBox.fireActionEvent(Unknown Source)
  at javax.swing.JComboBox.contentsChanged(Unknown Source)
  at javax.swing.AbstractListModel.fireContentsChanged(Unknown Source)
  at javax.swing.DefaultComboBoxModel.setSelectedItem(Unknown Source)
  at javax.swing.DefaultComboBoxModel.addElement(Unknown Source)
  at javax.swing.JComboBox.addItem(Unknown Source)
  at net.java.maven_jenkins_tool.JenkinsRemoteRegressionTool.JenkinsTool$6.itemStateChanged(JenkinsTool.java:789)
  </code></pre>
  
  <p>This is line 789: <code>comboBox.addItem(jenkinsName);</code></p>
  
  <p>This is line 851: <code>String getNodeViewJson = Get(selectedViewURL + "/api/json?pretty=true");</code></p>
  
  <p>The latter line is of course not getting triggered because that "SelectedViewURL" string is seen as NULL due to the ComboBox selection issue I'm experiencing.</p>