Java Code Examples for javax.swing.ComboBoxModel#getElementAt()

The following examples show how to use javax.swing.ComboBoxModel#getElementAt() . 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: SettingsPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Selects a given template.
 *
 * @param  templatePath  path of the template which should be selected;
 *                       may be <code>null</code> - then no item is selected
 */
void selectTemplate(String templatePath) {
    if (templatePath == null) {
        return;
    }
    
    ComboBoxModel model = cboTemplate.getModel();
    int itemsCount = model.getSize();
    
    if (itemsCount == 0) {
        return;
    }
    
    for (int i = 0; i < itemsCount; i++) {
        NamedObject namedObj = (NamedObject) model.getElementAt(i);
        FileObject template = (FileObject) namedObj.object;
        if (template.getPath().equals(templatePath)) {
            cboTemplate.setSelectedIndex(i);
            return;
        }
    }
}
 
Example 2
Source File: FieldPanel.java    From quickfix-messenger with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void setValue(String value)
{
	if (fieldComboBox != null)
	{
		ComboBoxModel<FieldValue> comboBoxModel = fieldComboBox.getModel();
		for (int i = 0; i < comboBoxModel.getSize(); i++)
		{
			FieldValue fieldValue = comboBoxModel.getElementAt(i);
			if (fieldValue.getEnumValue().equals(value))
			{
				fieldComboBox.setSelectedIndex(i);
			}
		}
	}

	else
	{
		fieldTextField.setText(value);
	}
}
 
Example 3
Source File: AjaxSpiderExplorer.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
public void optionsLoaded(QuickStartParam quickStartParam) {
    getSelectCheckBox().setSelected(quickStartParam.isAjaxSpiderEnabled());
    String def = quickStartParam.getAjaxSpiderDefaultBrowser();
    if (def == null || def.length() == 0) {
        // no default
        return;
    }
    ComboBoxModel<ProvidedBrowserUI> model = this.getBrowserComboBox().getModel();
    for (int idx = 0; idx < model.getSize(); idx++) {
        ProvidedBrowserUI el = model.getElementAt(idx);
        if (el.getName().equals(def)) {
            model.setSelectedItem(el);
            break;
        }
    }
}
 
Example 4
Source File: ColorPaletteChooser.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public Range getRangeFromFile() {
    final ComboBoxModel<ColorPaletteWrapper> model = getModel();
    final int selectedIndex = getSelectedIndex();
    final ColorPaletteWrapper paletteWrapper = model.getElementAt(selectedIndex);
    String name = paletteWrapper.name;
    final ColorPaletteDef cpd;
    if (name.startsWith(DERIVED_FROM)) {
        name = name.substring(DERIVED_FROM.length()).trim();
        if (name.toLowerCase().endsWith(".cpd")) {
            name = FileUtils.getFilenameWithoutExtension(name);
        }
        cpd = findColorPalette(name);
    } else {
        cpd = paletteWrapper.cpd;
    }
    return new Range(cpd.getMinDisplaySample(), cpd.getMaxDisplaySample());
}
 
Example 5
Source File: ScopePanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    ComboBoxModel m = this.scopeCombobox.getModel();
    ScopeProvider selectedScope = (ScopeProvider) scopeCombobox.getSelectedItem();
    Scope scope = selectedScope.getScope();
    if (selectedScope instanceof DelegatingCustomScopeProvider) {
        showCustomizer((DelegatingCustomScopeProvider) selectedScope, scope);
    } else {
        for (int i = 0; i < m.getSize(); i++) {
            ScopeProvider sd = (ScopeProvider) m.getElementAt(i);

            if (sd instanceof DelegatingCustomScopeProvider) {
                showCustomizer((DelegatingCustomScopeProvider) sd, scope);
                break;
            }
        }
    }
}
 
Example 6
Source File: ScopePanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void selectPreferredScope() {
    ComboBoxModel m = scopeCombobox.getModel();

    for (int i = 0; i < m.getSize(); i++) {
        DelegatingScopeInformation sd = (DelegatingScopeInformation) m.getElementAt(i);

        if (sd.getPosition() >= 0) {
            scopeCombobox.setSelectedItem(sd);
            return;
        }
    }
}
 
Example 7
Source File: ColorPaletteChooser.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public ColorPaletteDef getSelectedColorPaletteDefinition() {
    final int selectedIndex = getSelectedIndex();
    final ComboBoxModel<ColorPaletteWrapper> model = getModel();
    final ColorPaletteWrapper colorPaletteWrapper = model.getElementAt(selectedIndex);
    final ColorPaletteDef cpd = colorPaletteWrapper.cpd;
    cpd.getFirstPoint().setLabel(colorPaletteWrapper.name);
    return cpd;
}
 
Example 8
Source File: AllLocalProductsRepositoryPanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public void deleteLocalRepositoryFolder(LocalRepositoryFolder localRepositoryFolderToRemove) {
    ComboBoxModel<LocalRepositoryFolder> foldersModel = this.foldersComboBox.getModel();
    for (int i = 0; i < foldersModel.getSize(); i++) {
        LocalRepositoryFolder existingFolder = foldersModel.getElementAt(i);
        if (existingFolder != null && existingFolder.getId() == localRepositoryFolderToRemove.getId()) {
            this.foldersComboBox.removeItemAt(i);
            break;
        }
    }
    if (foldersModel.getSize() == 1 && foldersModel.getElementAt(0) == null) {
        this.foldersComboBox.removeItemAt(0);
    }
}
 
Example 9
Source File: SimulateOptions.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
private void loadSimLimit(Integer val) {
	int value = val.intValue();
	ComboBoxModel<Object> model = simLimit.getModel();
	for (int i = 0; i < model.getSize(); i++) {
		Integer opt = (Integer) model.getElementAt(i);
		if (opt.intValue() == value) {
			simLimit.setSelectedItem(opt);
		}
	}
}
 
Example 10
Source File: KeyMapOperator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void selectProfile(String profile) {
    JComboBoxOperator combo = profile();
    if (combo.getSelectedItem().toString().equals(profile)) {
        return; //no need to switch profile
    }
    ComboBoxModel model = combo.getModel();
    for (int i = 0; i < model.getSize(); i++) {
        Object item = model.getElementAt(i);
        if (item.toString().equals(profile)) {
            combo.setSelectedIndex(i);
            return;
        }
    }
    throw new IllegalArgumentException("Profile " + profile + " not found");
}
 
Example 11
Source File: AllLocalProductsRepositoryPanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public List<LocalRepositoryFolder> getLocalRepositoryFolders() {
    ComboBoxModel<LocalRepositoryFolder> foldersModel = this.foldersComboBox.getModel();
    List<LocalRepositoryFolder> result = new ArrayList<>(foldersModel.getSize());
    for (int i = 0; i < foldersModel.getSize(); i++) {
        LocalRepositoryFolder existingFolder = foldersModel.getElementAt(i);
        if (existingFolder != null) {
            result.add(existingFolder);
        }
    }
    return result;
}
 
Example 12
Source File: DataTypeEditorManager.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected void setCallingConvention(String callingConvention) {
	ComboBoxModel<?> model = callingConventionComboBox.getModel();
	int size = model.getSize();
	for (int i = 0; i < size; i++) {
		Object item = model.getElementAt(i);
		if (item.equals(callingConvention)) {
			callingConventionComboBox.setSelectedItem(callingConvention);
			return;
		}
	}

	callingConventionComboBox.setSelectedItem(GenericCallingConvention.unknown);
}
 
Example 13
Source File: FmtOptions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static ComboItem whichItem(String value, ComboBoxModel model) {

            for (int i = 0; i < model.getSize(); i++) {
                ComboItem item = (ComboItem) model.getElementAt(i);
                if (value.equals(item.value)) {
                    return item;
                }
            }
            return null;
        }
 
Example 14
Source File: RemoteUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public int selectionForKey(char key, ComboBoxModel model) {
    char firstChar = ("" + key).toLowerCase().charAt(0); // NOI18N
    for (int i = 0; i < model.getSize(); ++i) {
        RemoteConfiguration configuration = (RemoteConfiguration) model.getElementAt(i);
        if (configuration.getDisplayName().charAt(0) == firstChar) {
            return i;
        }
    }
    return -1;
}
 
Example 15
Source File: ClientInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Object getPackageItem(String name) {
    Object result = name;
    
    ComboBoxModel model = jCbxPackageName.getModel();
    int max = model.getSize();
    for (int i = 0; i < max; i++) {
        Object item = model.getElementAt(i);
        if(item.toString().equals(name)) {
            result = item;
            break;
        }
    }
    
    return result;
}
 
Example 16
Source File: ColorPaletteChooser.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private ColorPaletteDef findColorPalette(String name) {
    final ComboBoxModel<ColorPaletteWrapper> model = getModel();
    for (int i = 0; i < model.getSize(); i++) {
        final ColorPaletteWrapper paletteWrapper = model.getElementAt(i);
        if (paletteWrapper.name.equals(name)) {
            return paletteWrapper.cpd;
        }
    }
    return null;
}
 
Example 17
Source File: FmtOptions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static ComboItem whichItem(String value, ComboBoxModel model) {

            for (int i = 0; i < model.getSize(); i++) {
                ComboItem item = (ComboItem)model.getElementAt(i);
                if ( value.equals(item.value)) {
                    return item;
                }
            }
            return null;
        }
 
Example 18
Source File: IndexSearch.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void mirrorMRUStrings() {
    ComboBoxModel model = searchComboBox.getModel();
    int size = model.getSize();
    MRU = new Object[size];
    for (int i = 0; i < size; i++) {
        MRU[i] = model.getElementAt(i);
    }
}
 
Example 19
Source File: PersistenceProviderComboboxHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the provider representing the default provider from
 * the given <code>providers</code>.
 * @param providers the providers. if the default provider is supported,
 * it has to be the first element in the model.
 * @return the default provider or null if is not supported.
 */ 
private Provider getDefaultProvider(ComboBoxModel providers){
    if (!providerSupplier.supportsDefaultProvider()){
        return null;
    }
    if (providers.getElementAt(0) instanceof Provider){
        return (Provider) providers.getElementAt(0);
    }
    return null;
}
 
Example 20
Source File: ActiveBagContentControlPanel.java    From jclic with GNU General Public License v2.0 4 votes vote down vote up
public void setActiveBagContent(ActiveBagContent abc, ActiveBagContent altAbc) {
  this.abc = abc;
  this.altAbc = altAbc;

  altNull = (altAbc == null);
  if (abc != null && !simpleMode)
    abc.checkCells();
  if (altAbc != null && !simpleMode)
    altAbc.checkCells();

  altChk.setSelected(!altNull);
  altChk.setEnabled(abc != null);
  toggleAlt.setSelected(false);
  toggleAlt.setEnabled(!altNull);
  imgButton.setMediaBagEditor(parent.mediaBagEditor);
  imgButton.setImgName(abc != null ? abc.imgName : null);
  imgButton.setEnabled(abc != null);
  boxBaseButton.setBoxBase(abc != null ? abc.bb : null);
  parent.abcpp.setActiveBagContent(visualIndex, abc, altAbc, null);
  boxBaseButton.setPreview(parent.abcpp.getAbstractBox(visualIndex));
  boxBaseButton.setEnabled(abc != null);
  Shaper sh = (abc != null ? abc.getShaper() : null);
  ComboBoxModel model = shaperCombo.getModel();
  int modelSize = model.getSize();
  int i = -1;
  if (sh != null) {
    String s = sh.getClassName();
    for (i = 0; i < modelSize; i++) {
      TripleString ts = (TripleString) model.getElementAt(i);
      if (s.equals(ts.getClassName()))
        break;
    }
  }
  shaperCombo.setSelectedIndex(i < modelSize ? i : -1);
  shaperCombo.setEnabled(abc != null);
  shaperEditBtn.setEnabled(sh != null && sh.getEditorPanelClassName() != null);
  nColsEdit.setValue(sh != null ? sh.getNumColumns() : 1);
  nColsEdit.setEnabled(abc != null);
  nRowsEdit.setValue(sh != null ? sh.getNumRows() : 1);
  nRowsEdit.setEnabled(abc != null);
  widthEdit.setValue(abc != null ? (int) abc.w : 30);
  widthEdit.setEnabled(abc != null);
  heightEdit.setValue(abc != null ? (int) abc.h : 20);
  heightEdit.setEnabled(abc != null);
  borderChk.setSelected(abc != null ? abc.border : false);
  borderChk.setEnabled(abc != null);
}