title: Binding HashMap to ComboBox
body: <p>Does anybody have an example of how to binding the keys of a HashMap to a ComboBox so that the changes in the HashMap are instantly reflected to the ComboBox?</p>
  
  <p>Thanks!</p>
  
  <p>EDIT:</p>
  
  <p>Solution thanks to "Hovercraft Full Of Eels":</p>
  
  <pre><code>private Map&lt;String, String&gt; format = new LinkedHashMap&lt;String,String&gt;();
  
      public class ToComboBoxModel&lt;String&gt; extends AbstractListModel&lt;String&gt; implements MutableComboBoxModel&lt;String&gt; {
  
          private String selectedItem;
  
          @Override
          public Object getSelectedItem() {
              return selectedItem;
          }
  
          @Override
          public void setSelectedItem(Object anItem) {
              // TODO Auto-generated method stub
              for (java.lang.String str : format.keySet()){
                  if (anItem.equals(str))
                  {
                      selectedItem=(String) str;
                      break;
                  }
              }
          }
  
          @Override
          public String getElementAt(int index) {         
              List&lt;Entry&lt;String,String&gt;&gt; randAccess = new ArrayList&lt;Entry&lt;String,String&gt;&gt;((Collection&lt;? extends Entry&lt;String, String&gt;&gt;) format.entrySet());
  
              return randAccess.get(index).getKey();
          }
  
          @Override
          public int getSize() {
              // TODO Auto-generated method stub
              return format.size();
          }
  
          @Override
          public void removeElement(Object obj) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void removeElementAt(int index) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void addElement(String item) {
  
  
          }
  
          @Override
          public void insertElementAt(String item, int index) {
              // TODO Auto-generated method stub
  
          }
      }
  </code></pre>