Java Code Examples for javax.swing.JComboBox.getModel()

The following are Jave code examples for showing how to use getModel() of the javax.swing.JComboBox class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: MultiDiffPanelController.java   Source Code and License Vote up 6 votes
private void addToModel (final Revision newItem, final JComboBox cmbDiffTree) {
    DefaultComboBoxModel model = (DefaultComboBoxModel) cmbDiffTree.getModel();
    for (int i = 0; i < model.getSize(); ++i) {
        final Object item = model.getElementAt(i);
        if (item instanceof Revision && ((Revision) item).getCommitId().equals(newItem.getCommitId())
                && ((Revision) item).getRevision().equals(newItem.getRevision())) {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run () {
                    cmbDiffTree.setSelectedItem(item);
                }
            });
            return;
        }
    }
    model.addElement(newItem);
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run () {
            cmbDiffTree.setSelectedItem(newItem);
        }
    });
}
 
Example 2
Project: incubator-netbeans   File: CopyDialogTest.java   Source Code and License Vote up 6 votes
private void assertModel (Map<String, String> items, JComboBox combo, List<String> expected) {
    ComboBoxModel model = combo.getModel();
    assertEquals(expected.size() / 2, model.getSize());
    for (int i = 0; i < model.getSize(); ++i) {
        assertEquals(expected.get(i * 2), model.getElementAt(i));
        assertEquals(expected.get(i * 2 + 1), items.get((String) model.getElementAt(i)));
    }
}
 
Example 3
Project: incubator-netbeans   File: IssuePanel.java   Source Code and License Vote up 6 votes
private boolean selectInCombo(JComboBox combo, Object value, boolean forceInModel) {
    if (value == null) {
        return false;
    }
    if (!value.equals(combo.getSelectedItem())) {
        combo.setSelectedItem(value);
    } 
    if (forceInModel && !value.equals("") && !value.equals(combo.getSelectedItem())) { // NOI18N
        // Reload of server attributes is needed - workarounding it
        ComboBoxModel model = combo.getModel();
        if (model instanceof DefaultComboBoxModel) {
            ((DefaultComboBoxModel)model).insertElementAt(value, 0);
            combo.setSelectedIndex(0);
        }
    }
    return value.equals(combo.getSelectedItem());
}
 
Example 4
Project: incubator-netbeans   File: ReturnTypeUIHelper.java   Source Code and License Vote up 5 votes
private static void performBrowseType(final JComboBox combo, final ClasspathInfo cpInfo) {
    final ReturnTypeComboBoxModel model = (ReturnTypeComboBoxModel) combo.getModel();
    combo.setPopupVisible(false);
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            final ElementHandle<TypeElement> handle = TypeElementFinder.find(cpInfo, new TypeElementFinder.Customizer() {
                public Set<ElementHandle<TypeElement>> query(ClasspathInfo classpathInfo, String textForQuery, NameKind nameKind, Set<SearchScope> searchScopes) {//GEN-LAST:event_browseButtonActionPerformed
                    return classpathInfo.getClassIndex().getDeclaredTypes(textForQuery, nameKind, searchScopes);
                }

                public boolean accept(ElementHandle<TypeElement> typeHandle) {
                    return true;
                }
            });

            combo.setPopupVisible(false);
            
            if (handle == null) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        setSelectedItem(combo, model.getPreviousItem());
                    }
                });
            } else {
                setSelectedItem(combo, handle.getQualifiedName());
            }
        }
    });
}
 
Example 5
Project: incubator-netbeans   File: IssuePanel.java   Source Code and License Vote up 5 votes
private String findInModel(JComboBox combo, String value) {
    ComboBoxModel model = combo.getModel();
    for(int i = 0; i < model.getSize(); i++) {
        String element = model.getElementAt(i).toString();
        if(value.toLowerCase().equals(element.toString().toLowerCase())) {
            return element;
        }
    }
    return null;
}
 
Example 6
Project: marathonv5   File: JComboBoxOptionJavaElement.java   Source Code and License Vote up 5 votes
private static Component getRendererComponent(JComboBox comboBox, int option) {
    ComboBoxModel model = comboBox.getModel();
    if (option >= model.getSize()) {
        throw new NoSuchElementException("Index out-of-bounds error on JComboBox: " + option, null);
    }
    Component rendererComponent = comboBox.getRenderer().getListCellRendererComponent(new JList(model),
            model.getElementAt(option), option, false, false);
    return rendererComponent;
}
 
Example 7
Project: incubator-netbeans   File: RepositoryComboSupport.java   Source Code and License Vote up 4 votes
private void checkOldComboBoxModel(JComboBox comboBox) {
    ComboBoxModel oldModel = comboBox.getModel();
    if ((oldModel != null) && (oldModel.getSize() != 0)) {
        throw new IllegalStateException("The combo-box must be empty."); //NOI18N
    }
}
 
Example 8
Project: gate-core   File: FeaturesSchemaEditor.java   Source Code and License Vote up 4 votes
protected void prepareCombo(JComboBox combo, int row, int column){
  Feature feature = featureList.get(row);
  DefaultComboBoxModel comboModel = (DefaultComboBoxModel)combo.getModel(); 
  comboModel.removeAllElements();
  switch(column){
    case NAME_COL:
      List<String> fNames = new ArrayList<String>();
      if(schema != null && schema.getFeatureSchemaSet() != null){
        Iterator<FeatureSchema> fSchemaIter = schema.getFeatureSchemaSet().iterator();
        while(fSchemaIter.hasNext())
          fNames.add(fSchemaIter.next().getFeatureName());
      }
      if(!fNames.contains(feature.name))fNames.add(feature.name);
      Collections.sort(fNames);
      for(Iterator<String> nameIter = fNames.iterator(); 
          nameIter.hasNext(); 
          comboModel.addElement(nameIter.next()));
      combo.getEditor().getEditorComponent().setBackground(defaultBackground);          
      combo.setSelectedItem(feature.name);
      break;
    case VALUE_COL:
      List<Object> fValues = new ArrayList<Object>();
      if(feature.isSchemaFeature()){
        Set<Object> permValues = schema.getFeatureSchema(feature.name).
          getPermittedValues();
        if(permValues != null) fValues.addAll(permValues);
      }
      if(!fValues.contains(feature.value)) fValues.add(feature.value);
      Collections.sort(fValues, defaultComparator);
      for(Iterator<Object> valIter = fValues.iterator(); 
          valIter.hasNext(); 
          comboModel.addElement(valIter.next()));
      combo.getEditor().getEditorComponent().setBackground(feature.isCorrect() ?
          defaultBackground :
          (feature.isRequired() ? REQUIRED_WRONG : OPTIONAL_WRONG));
      combo.setSelectedItem(feature.value);
      break;
    default: ;
  }
  
}