title: Swing MVC - refresh the content of JComboBox while already visible
body: <p>I set the model of my combobox in my controller class</p>
  
  <p><code>cboCategory.setModel(new ModernDefaultComboBoxModel(model.getProductCategories()));</code></p>
  
  <p><code>productCategories</code> is a <code>List</code> of <code>String</code>. <code>ModernDefaultComboBoxModel</code> is just model that extends <code>DefaultComboBoxModel</code>.</p>
  
  <pre><code>public class ModernDefaultComboBoxModel extends DefaultComboBoxModel{
      public ModernDefaultComboBoxModel(List&lt;String&gt; elements){
          super(elements.toArray());
      }
  }
  </code></pre>
  
  <p>Now in my model, <code>productCategories</code> is populated from the DB, in a <code>SwingWorker</code></p>
  
  <pre><code>SwingWorker&lt;Void, String&gt; worker = new SwingWorker&lt;Void, String&gt;() {
      @Override
      protected Void doInBackground() throws Exception {
          //query and resultset stuff
          while (rs.next()) {
              publish(rs.getString(1));
          }
          //cleanup stuff
      }
      @Override protected void process(List&lt;String&gt; chunks){
          List&lt;String&gt; oldCategories = new ArrayList&lt;String&gt;(productCategories);
          for(String cat : chunks){
              productCategories.add(cat);
          }
          fireModelPropertyChange(PRODUCT_CATEGORIES, oldCategories, productCategories);
      }
      @Override
      protected void done(){
          //some stuff
      }
  };
  worker.execute();
  </code></pre>
  
  <p>You see every <code>publish</code>, it fires a property change event to its listener (<code>fireModelPropertyChange</code> is just a wrapper for <code>firePropertyChange</code>).</p>
  
  <p>Now in my model listener,</p>
  
  <pre><code>@Override
      public void propertyChange(PropertyChangeEvent evt) {
          String propName = evt.getPropertyName();
  
          //some branching for the other models
  
          else if(ProductModel.PRODUCT_CATEGORIES.equals(propName)){
              List&lt;String&gt; newVal = (List&lt;String&gt;)evt.getNewValue();
  
              //notify the model of the combobox that the data is changed, so refresh urself
          }
  
          //some stuff
      }
  </code></pre>
  
  <p>I'm stuck in the part where my <code>ModelListener</code> needs to notify the combobox in the view that data in its model are changed. I have the same situation with <code>JTable</code> but with <code>JTable</code> I can just call <code>fireTableRowsInserted</code> of from its model which is implemented from <code>AbstractTableModel</code>.</p>
  
  <p>Actually, in the <code>AbstractListModel</code> there is a method <code>fireContentsChanged</code> but unlike in the <code>JTable</code>, this method is protected so I can't access it.</p>
  
  <p>I know I can just create an instance of <code>ModernDefaultComboBoxModel</code> then call the <code>setModel</code> method of the combobox  to refresh the combobox, but I'm just wondering if there is a "cleaner" way as clean as that of <code>JTable</code></p>