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

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

源代码1 项目: netbeans   文件: LicenseHeadersPanel.java
private boolean selectComboBoxItem(String name, boolean setText) {
    boolean found = false;
    DefaultComboBoxModel model = (DefaultComboBoxModel) comGlobal.getModel();
    for (int i = 0; i < model.getSize(); i++) {
        GlobalItem gi = (GlobalItem) model.getElementAt(i);
        if (gi.getName().equals(name)) {
            comGlobal.setSelectedItem(gi);
            found = true;
            if (setText) {
                setTextToGlobalLicense();
            }
            break;
        }
    }
    if (!found) {
        GlobalItem itm = new GlobalItem(name, null);
        model.insertElementAt(itm, 0);
        comGlobal.setSelectedItem(itm);
        if (setText) {
            setTextToGlobalLicense();
        }
    }
    return found;
}
 
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 项目: open-ig   文件: GUIUtils.java
/**
   * Checks if the item is in the combobox. If yes, then it is moved to the beginning,
   * otherwise, the item is added as first.
   * @param <T> the element type
   * @param combobox the combobox
   * @param item the item
   */
  public static <T> void addFirstItem(JComboBox<T> combobox, T item) {
  	int idx = -1;
  	DefaultComboBoxModel<T> model = (DefaultComboBoxModel<T>)combobox.getModel();
for (int i = 0; i < model.getSize(); i++) {
  		T t = model.getElementAt(i);
  		if (Objects.equals(t, item)) {
  			idx = i;
  			break;
  		}
  	}
model.insertElementAt(item, 0);
  	if (idx >= 0) {
  		model.removeElementAt(idx + 1);
  	}
  }
 
源代码4 项目: pentaho-reporting   文件: ColorComboBox.java
/**
 * Creates a new color combobox and populates it with the excel colors.
 */
public ColorComboBox() {
  final DefaultComboBoxModel model = new DefaultComboBoxModel( ColorUtility.getPredefinedExcelColors() );
  model.insertElementAt( null, 0 );
  model.setSelectedItem( null );

  setModel( model );
  setRenderer( new ColorCellRenderer() );
  final int height1 = getPreferredSize().height;
  setMaximumSize( new Dimension( height1 * 4, height1 ) );
  setFocusable( false );

  final boolean isGTK = isGTKLookAndFeel();
  setEditable( isGTK );

  // if it's GTK LnF, we have to customize the combo box since GTK Lnf ignores the <i>setBackground</i>
  if ( isGTK ) {
    setEditor( new CustomGTKComboBoxEditor() );
  }
}
 
源代码5 项目: nmonvisualizer   文件: SummaryTablePanel.java
private void updateStatisticsComboBox() {
    String newName = Statistic.GRANULARITY_MAXIMUM.getName(gui.getGranularity());

    @SuppressWarnings("unchecked")
    DefaultComboBoxModel<Object> model = (DefaultComboBoxModel<Object>) ((JComboBox<Object>) statsPanel
            .getComponent(1)).getModel();

    boolean reselect = false;

    if (model.getSelectedItem() == model.getElementAt(4)) {
        reselect = true;
    }

    model.removeElementAt(4);
    model.insertElementAt(newName, 4);

    if (reselect) {
        model.setSelectedItem(newName);
    }
}
 
源代码6 项目: netbeans   文件: DirectorySelectorCombo.java
private ComboListElement addPath(String path) {
  DefaultComboBoxModel model = (DefaultComboBoxModel)fileMRU.getModel();
  ComboListElement newPath = new StringComboListElement(path);
  int index = model.getIndexOf(newPath);
  if (index == -1) {
    model.insertElementAt(newPath, 1);
  }
  if (model.getSize() > itemCountLimit + 3) {
    model.removeElementAt(model.getSize() - 3);
  }
  return newPath;
}
 
源代码7 项目: 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);
}
 
源代码8 项目: netbeans   文件: TemplateChooserPanelGUI.java
private void selectProject (@NullAllowed Project p) {
    if (p != null) {
        DefaultComboBoxModel projectsModel = (DefaultComboBoxModel) projectsComboBox.getModel ();
        if ( projectsModel.getIndexOf( p ) == -1 ) {
            projectsModel.insertElementAt( p, 0 );
        }
        projectsComboBox.setSelectedItem( p );
    } 
    else {
        projectsComboBox.setSelectedItem(null);
    }
}
 
源代码9 项目: gate-core   文件: LuceneDataStoreSearchGUI.java
protected void updateAnnotationSetsList() {
  String corpusName =
          (corpusToSearchIn.getSelectedItem()
                  .equals(Constants.ENTIRE_DATASTORE))
                  ? null
                  : (String)corpusIds
                          .get(corpusToSearchIn.getSelectedIndex() - 1);
  TreeSet<String> ts = new TreeSet<String>(stringCollator);
  ts.addAll(getAnnotationSetNames(corpusName));
  DefaultComboBoxModel<String> dcbm = new DefaultComboBoxModel<String>(ts.toArray(new String[ts.size()]));
  dcbm.insertElementAt(Constants.ALL_SETS, 0);
  annotationSetsToSearchIn.setModel(dcbm);
  annotationSetsToSearchIn.setSelectedItem(Constants.ALL_SETS);

  // used in the ConfigureStackViewFrame as Annotation type column
  // cell editor
  TreeSet<String> types = new TreeSet<String>(stringCollator);
  types.addAll(getTypesAndFeatures(null, null).keySet());
  // put all annotation types from the datastore
  // combobox used as cell editor
  JComboBox<String> annotTypesBox = new JComboBox<String>();
  annotTypesBox.setMaximumRowCount(10);
  annotTypesBox.setModel(new DefaultComboBoxModel<String>(types.toArray(new String[types.size()])));
  DefaultCellEditor cellEditor = new DefaultCellEditor(annotTypesBox);
  cellEditor.setClickCountToStart(0);
  configureStackViewFrame.getTable().getColumnModel()
          .getColumn(ANNOTATION_TYPE).setCellEditor(cellEditor);
}
 
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);
        }
    }
}
 
源代码11 项目: java-ocr-api   文件: DemoUtils.java
public static void savePrefs(Preferences prefs, String prefKey, JComboBox combo, String newValidValue) {
    if (newValidValue == null) { 
        return;
    }

    DefaultComboBoxModel comboModel = (DefaultComboBoxModel) combo.getModel();

    int existingIndex = comboModel.getIndexOf(newValidValue);
    if (existingIndex >= 0) { 
        comboModel.removeElementAt(existingIndex);
    }
    comboModel.insertElementAt(newValidValue, 0);
    combo.setSelectedIndex(0);

    StringBuilder entries = new StringBuilder();
    int size = Math.min(comboModel.getSize(), 20); 
    for (int i = 0; i < size; i++) {
        entries.append(comboModel.getElementAt(i));
        if (i != size - 1) { 
            entries.append(DELIMITER);
        }
    }

    while (entries.length() > Preferences.MAX_VALUE_LENGTH) {
        int lastIndex = entries.lastIndexOf(DELIMITER);
        if (lastIndex == -1) {
            break;
        } else {
            entries.delete(lastIndex, entries.length());
        }
    }

    prefs.put(prefKey, entries.toString());
    try {
        prefs.flush();
    } catch (Throwable e) {
        e.printStackTrace();
    }
}