javax.swing.DefaultComboBoxModel#removeElement ( )源码实例Demo

下面列出了javax.swing.DefaultComboBoxModel#removeElement ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: SelectProjectPanel.java
private void btnProjectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProjectActionPerformed
    JFileChooser chooser = ProjectChooser.projectChooser();
    int res = chooser.showOpenDialog(SwingUtilities.getWindowAncestor(this));
    if (res == JFileChooser.APPROVE_OPTION) {
        File fil = chooser.getSelectedFile();
        FileObject fo = FileUtil.toFileObject(fil);
        if (fo != null) {
            try {
                Project p = ProjectManager.getDefault().findProject(fo);
                DefaultComboBoxModel model = (DefaultComboBoxModel)comProject.getModel();
                model.addElement(p);
                model.setSelectedItem(p);
                if (EMPTY == model.getElementAt(0)) {
                    model.removeElement(EMPTY);
                }
            } catch (IOException exc) {
                ErrorManager.getDefault().notify(exc);
            }
        }
    }
}
 
private void renameEmulator() {
    String oldName = browserCombo.getSelectedItem().toString();
    String newEmName = browserCombo.getEditor().getItem().toString();
    if (!oldName.equals(newEmName)) {
        if (!getTotalBrowserList().contains(newEmName)) {
            Emulator emulator = settings.getEmulators().getEmulator(oldName);
            emulator.setName(newEmName);
            DefaultComboBoxModel combomodel = (DefaultComboBoxModel) browserCombo.getModel();
            DefaultComboBoxModel dupCombomodel = (DefaultComboBoxModel) dupDriverCombo.getModel();
            int index = browserCombo.getSelectedIndex();
            combomodel.removeElement(oldName);
            dupCombomodel.removeElement(oldName);
            combomodel.insertElementAt(newEmName, index);
            dupCombomodel.insertElementAt(newEmName, index);
            browserCombo.setSelectedIndex(index);
        } else {
            Notification.show("Emulator/Browser [" + newEmName + "] already Present");
        }
    }
}
 
源代码3 项目: netbeans   文件: DirectorySelectorCombo.java
private void fileMRUPopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_fileMRUPopupMenuWillBecomeVisible
  DefaultComboBoxModel model = (DefaultComboBoxModel)fileMRU.getModel();
  Collection mukls = new ArrayList();
  for(int i=0;i<model.getSize();i++) {
    if (!(model.getElementAt(i) instanceof ComboListElement))
      continue;
    if (((ComboListElement)model.getElementAt(i)).isVolatile())
      mukls.add(model.getElementAt(i));
  }
  for (Iterator it = mukls.iterator(); it.hasNext();) {
    Object elem = (Object) it.next();
    model.removeElement(elem);
    it.remove();
  }
}
 
源代码4 项目: netbeans   文件: RunAsRemoteWeb.java
private void selectRemoteConnection(String remoteConnection) {
    if (remoteConnection == null) {
        remoteConnection = getValue(PhpProjectProperties.REMOTE_CONNECTION);
    }
    // #141849 - can be null if one adds remote config for the first time for a project but already has some remote connection
    DefaultComboBoxModel<RemoteConfiguration> model = (DefaultComboBoxModel<RemoteConfiguration>) remoteConnectionComboBox.getModel();
    if (remoteConnection == null
            || RunConfigRemote.NO_CONFIG_NAME.equals(remoteConnection)) {
        if (model.getIndexOf(RunConfigRemote.NO_REMOTE_CONFIGURATION) < 0) {
            model.insertElementAt(RunConfigRemote.NO_REMOTE_CONFIGURATION, 0);
        }
        remoteConnectionComboBox.setSelectedItem(RunConfigRemote.NO_REMOTE_CONFIGURATION);
        return;
    }

    int size = remoteConnectionComboBox.getModel().getSize();
    for (int i = 0; i < size; ++i) {
        RemoteConfiguration rc = remoteConnectionComboBox.getItemAt(i);
        if (remoteConnection.equals(rc.getName())) {
            remoteConnectionComboBox.setSelectedItem(rc);
            return;
        }
    }

    // remote connection is missing (probably removed?)
    remoteConnectionComboBox.addItem(RunConfigRemote.MISSING_REMOTE_CONFIGURATION);
    remoteConnectionComboBox.setSelectedItem(RunConfigRemote.MISSING_REMOTE_CONFIGURATION);
    // # 162230
    model.removeElement(RunConfigRemote.NO_REMOTE_CONFIGURATION);
}
 
private void renameModule() {
    if (moduleCombo.getSelectedIndex() != -1) {
        String moduleName = moduleCombo.getSelectedItem().toString();
        String newModuleName = moduleCombo.getEditor().getItem().toString();
        if (!newModuleName.trim().isEmpty()) {
            testMgmtModule.getModule(moduleName).setModule(newModuleName);
            DefaultComboBoxModel combomodel = (DefaultComboBoxModel) moduleCombo.getModel();
            int index = moduleCombo.getSelectedIndex();
            combomodel.removeElement(moduleName);
            combomodel.insertElementAt(newModuleName, index);
            moduleCombo.setSelectedIndex(index);
        }
    }
}
 
源代码6 项目: pentaho-reporting   文件: JdbcDataSourceDialog.java
public void actionPerformed( final ActionEvent e ) {
  final NamedDataSourceDialogModel dialogModel = getDialogModel();
  final DefaultComboBoxModel queries = dialogModel.getQueries();
  queries.removeElement( queries.getSelectedItem() );
  if ( queryNameList.getLastVisibleIndex() != -1 ) {
    queryNameList.setSelectedValue( dialogModel.getQueries().getQuery( queryNameList.getLastVisibleIndex() ), true );
    queryNameList.setSelectedIndex( queryNameList.getLastVisibleIndex() );
    queries.setSelectedItem( dialogModel.getQueries().getQuery( queryNameList.getLastVisibleIndex( ) ) );
    queryTextArea.setEnabled( true );
  } else {
    queries.setSelectedItem( null );
    queryNameList.clearSelection();
    queryTextArea.setEnabled( false );
  }
}
 
源代码7 项目: rapidminer-studio   文件: ConfigureDataView.java
private void guessDateFormatForPreview(String preferredPattern) {
	if (!requiresDateFormat) {
		return;
	}

	// Keep the currentCustomFormat, lastCustomFormat and the dataSetMetaData format

	List<String> customPatterns = new ArrayList<>();
	Optional.ofNullable(dateFormatField.getSelectedItem()).map(Object::toString).ifPresent(customPatterns::add);
	Optional.ofNullable(lastCustomDateFormat).map(MatchingEntry::getEntryName).ifPresent(customPatterns::add);
	Stream.of(dataSetMetaData.getDateFormat()).filter(SimpleDateFormat.class::isInstance).map(SimpleDateFormat.class::cast).map(SimpleDateFormat::toPattern).forEach(customPatterns::add);

	DateFormatGuesser dateFormatGuesser = null;
	try {
		dateFormatGuesser = DateFormatGuesser.guessDateFormat(tableModel.getDataSet(), customPatterns, preferredPattern);
	} catch (DataSetException e) {
		SwingTools.invokeLater(() -> showErrorNotification(ERROR_LOADING_DATA_KEY, e.getMessage()));
	}
	if (dateFormatGuesser == null) {
		dfg = null;
		return;
	}
	SimpleDateFormat bestDateFormat = dateFormatGuesser.getBestMatch(DATE_COLUMN_CONFIDENCE);
	String bestPattern = bestDateFormat != null ? bestDateFormat.toPattern() : null;
	MatchingEntry bestMatchingEntry = null;
	Map<String, Double> results = dateFormatGuesser.getResults(DATE_COLUMN_CONFIDENCE);
	/// update existing entries with new match values
	for (MatchingEntry matchingEntry : matchingEntries) {
		String entryName = matchingEntry.getEntryName();
		double match = results.getOrDefault(entryName, 0d);
		matchingEntry.setMatch(match);
		if (entryName.equals(bestPattern)) {
			bestMatchingEntry = matchingEntry;
		}
	}

	// add new entry
	if (bestPattern != null && bestMatchingEntry == null) {
		bestMatchingEntry = MatchingEntry.create(bestPattern, results.getOrDefault(bestPattern, 0d));
		DefaultComboBoxModel<MatchingEntry> comboBoxModel = (DefaultComboBoxModel<MatchingEntry>) dateFormatField.getModel();
		if (lastCustomDateFormat != null) {
			comboBoxModel.removeElement(lastCustomDateFormat);
		}
		comboBoxModel.addElement(bestMatchingEntry);
		lastCustomDateFormat = bestMatchingEntry;
	}
	matchingEntries.sort(MatchingEntry::compareTo);
	if (bestDateFormat != null) {
		dataSetMetaData.setDateFormat(bestDateFormat);
	}
	if (guessedDateFormat == null) {
		guessedDateFormat = bestPattern != null ? bestPattern : "";
	}
	dfg = dateFormatGuesser;
}
 
源代码8 项目: pentaho-reporting   文件: QueryRemoveAction.java
public void actionPerformed( final ActionEvent e ) {
  final DefaultComboBoxModel comboBoxModel = queries.getQueries();
  comboBoxModel.removeElement( comboBoxModel.getSelectedItem() );
  comboBoxModel.setSelectedItem( null );
}