下面列出了javax.swing.DefaultComboBoxModel#removeElement ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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");
}
}
}
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();
}
}
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);
}
}
}
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 );
}
}
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;
}
public void actionPerformed( final ActionEvent e ) {
final DefaultComboBoxModel comboBoxModel = queries.getQueries();
comboBoxModel.removeElement( comboBoxModel.getSelectedItem() );
comboBoxModel.setSelectedItem( null );
}