title: Java swing: implementing my Comboboxmodel for JComboBox
body: <p>I need my combo box to have short names of organizations. The problem is i <strong>can</strong> see organizations names in dropdown list, but <strong>cant</strong> actually select it. Where is my mistake?</p>
  
  <pre><code>public class ToComboBoxModel extends AbstractListModel implements ComboBoxModel {
        private String selectedItem;
  
        private List&lt;Organization&gt; orgs;
  
        public ToComboBoxModel(List orgs) {
          this.orgs = orgs;
        }
  
          @Override
        public String getSelectedItem() {
  
          return selectedItem;
        }
  
          @Override
        public void setSelectedItem(Object newValue) {
              for (Organization o: orgs){
                  if (newValue==o){
                      selectedItem=o.getShortName();
                      break;
                  }
              }
        }
  
          @Override
        public int getSize() {
          return orgs.size();
        }
  
          @Override
        public String getElementAt(int i) {
          return orgs.get(i).getShortName();
        }
      }
  </code></pre>
  
  <p>Setting model:</p>
  
  <pre><code>query =session.createQuery("from Organization where isMain = 0");
  List orgs=query.list();
  toComboBox.setModel(new ToComboBoxModel(orgs));
  </code></pre>
  
  <p>Thanks in advance!</p>