Java Code Examples for javax.swing.DefaultComboBoxModel#removeAllElements()

The following examples show how to use javax.swing.DefaultComboBoxModel#removeAllElements() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditDriveOrderPanel.java    From openAGV with Apache License 2.0 6 votes vote down vote up
/**
 * Aktualisiert den Inhalt der ComboBox mit den Aktionen. Wird aufgerufen,
 * wenn in der ComboBox mit den Stationen ein anderes Element ausgewählt
 * wurde.
 *
 * @param evt das auslösende Ereignis
 */
private void locationComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_locationComboBoxActionPerformed
  DefaultComboBoxModel<String> model
      = (DefaultComboBoxModel<String>) actionComboBox.getModel();
  model.removeAllElements();

  getSelectedLocation().ifPresent(location -> {
    LocationTypeModel type = location.getLocationType();
    StringSetProperty p = type.getPropertyAllowedOperations();
    for (String item : new ArrayList<>(type.getPropertyAllowedOperations().getItems())) {
      model.addElement(item);
    }

    if (model.getSize() > 0) {
      actionComboBox.setSelectedIndex(0);
    }
  });
}
 
Example 2
Source File: LoginDialog.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
protected void onShow() {
   List<OculusSession> recentSessions = ServiceLocator.getInstance(SessionController.class).listRecentSessions();
   if(!lastSessions.equals(recentSessions)) {
      lastSessions = recentSessions;
      DefaultComboBoxModel<OculusSession> model = ((DefaultComboBoxModel<OculusSession>) serviceUri.getModel());
      model.removeAllElements();
      for(OculusSession hau: ServiceLocator.getInstance(SessionController.class).listRecentSessions()) {
         model.addElement(hau);
      }
   }

   if(username.getText().isEmpty()) {
      username.requestFocusInWindow();
   }
   else {
      password.requestFocusInWindow();
   }
}
 
Example 3
Source File: DirectorySelectorCombo.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void changeModel() {
  DefaultComboBoxModel model = (DefaultComboBoxModel)fileMRU.getModel();
  model.removeAllElements();
  if (isShowWelcome()) {
    model.addElement(new StringComboListElement(getWelcomeText(), true));
  }
  model.addElement(new ComboListElement(getNoneText()) {
    public void onSelection() {
      validSelection = false;
    }
  });
  JSeparator separ = new JSeparator();
  model.addElement(separ);
  model.addElement(new ComboListElement(getActionText()) {
    public void onSelection() {
      validSelection = false;
      browseFiles();
    }
  });
}
 
Example 4
Source File: XgappUpgradeSelector.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
  JComboBox<UpgradeXGAPP.UpgradePath.UpgradeStrategy> combo = (JComboBox)super.getTableCellEditorComponent(table, value, isSelected, row, column);
  DefaultComboBoxModel<UpgradeXGAPP.UpgradePath.UpgradeStrategy> model = (DefaultComboBoxModel)combo.getModel();
  model.removeAllElements();
  if(((String)table.getValueAt(row, 0)).startsWith("<html>")) {
    // directory plugin
    model.addElement(UpgradeXGAPP.UpgradePath.UpgradeStrategy.UPGRADE);
    model.addElement(UpgradeXGAPP.UpgradePath.UpgradeStrategy.PLUGIN_ONLY);
    model.addElement(UpgradeXGAPP.UpgradePath.UpgradeStrategy.SKIP);
  } else {
    // old $gatehome$ or existing Maven
    model.addElement(UpgradeXGAPP.UpgradePath.UpgradeStrategy.UPGRADE);
    model.addElement(UpgradeXGAPP.UpgradePath.UpgradeStrategy.SKIP);
  }
  combo.setSelectedItem(value); // which must be one of the available ones
  return combo;
}
 
Example 5
Source File: AttackPanel.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
private void setRecentUrls() {
    if (urlField != null) {
        QuickStartParam quickStartParam = this.getExtensionQuickStart().getQuickStartParam();
        Object currentUrl = urlField.getSelectedItem();
        DefaultComboBoxModel<String> model = getUrlModel();
        model.removeAllElements();
        List<Object> recentUrls = quickStartParam.getRecentUrls();
        for (Object url : recentUrls) {
            if (url != null) {
                model.addElement(url.toString());
            }
        }
        if (currentUrl != null && currentUrl.toString().length() > 0) {
            urlField.setSelectedItem(currentUrl);
        } else {
            urlField.setSelectedItem(DEFAULT_VALUE_URL_FIELD);
        }
    }
}
 
Example 6
Source File: MediaFormatWnd.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
private void addToModel(DefaultComboBoxModel<String> model, List<String> list, String defaultValue,
		JComboBox<String> cmb) {
	model.removeAllElements();
	if (list == null) {
		return;
	}
	for (String s : list) {
		model.addElement(s);
	}
	if (!StringUtils.isNullOrEmptyOrBlank(defaultValue)) {
		cmb.setSelectedItem(defaultValue);
	}
}
 
Example 7
Source File: ResolveBrokenRuntimePlatform.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void updatePlatforms() {
    final SourceLevelQuery.Result slqr = SourceLevelQuery.getSourceLevel2(prj.getProjectDirectory());
    final String sl = slqr.getSourceLevel();
    final SourceLevelQuery.Profile profile = slqr.getProfile();
    final DefaultComboBoxModel<Object> model = (DefaultComboBoxModel<Object>) platforms.getModel();
    model.removeAllElements();
    for (J2SERuntimePlatformProvider pp : prj.getLookup().lookupAll(J2SERuntimePlatformProvider.class)) {
        for (JavaPlatform jp : pp.getPlatformType(new SpecificationVersion(sl), profile)) {
            model.addElement(jp);
        }
    }
}
 
Example 8
Source File: XgappUpgradeSelector.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
  JComboBox<Version> combo = (JComboBox<Version>)super.getTableCellEditorComponent(table, value, isSelected, row, column);
  DefaultComboBoxModel<Version> model = (DefaultComboBoxModel<Version>)combo.getModel();
  model.removeAllElements();
  UpgradeXGAPP.UpgradePath path = (UpgradeXGAPP.UpgradePath)table.getValueAt(row, -1);
  for(Version v : path.getVersions()) {
    model.addElement(v);
  }
  combo.setSelectedItem(value); // which must be one of the available ones
  return combo;
}
 
Example 9
Source File: InitializrProjectPanelVisual1.java    From nb-springboot with Apache License 2.0 5 votes vote down vote up
private void fillCombo(JsonNode attrNode, DefaultComboBoxModel<NamedItem> comboModel, JComboBox combo) {
    JsonNode valArray = attrNode.path("values");
    comboModel.removeAllElements();
    for (JsonNode val : valArray) {
        comboModel.addElement(new NamedItem(val.get("id").asText(), val.get("name").asText()));
    }
    combo.setModel(comboModel);
    combo.setSelectedItem(new NamedItem(attrNode.path("default").asText(), ""));
}
 
Example 10
Source File: TabPanelCareer.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public void checkRoleChange() {

		List<String> names = getRoleNames();
		
        DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) roleComboBox.getModel();
        
        int oldSize = model.getSize();
        
        if (oldSize != names.size()) {
	        // removing old data
	        model.removeAllElements();
	
	        for (String item : names) {
	            model.addElement(item);
	        }
	        // setting model with new data
	        roleComboBox.setModel(model);
        }

		// Prepare role combo box
		String newRole = person.getRole().getType().toString();

		if (!roleCache.equalsIgnoreCase(newRole)) {
			roleCache = newRole;
			roleComboBox.setSelectedItem(roleCache);
			
			String s = person + "'s role has just been changed to " + newRole;
			roleChangeLabel.setText(s);
		}
	}
 
Example 11
Source File: FeaturesSchemaEditor.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
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: ;
  }
  
}