Java Code Examples for javax.swing.JComboBox.getItemAt()

The following are Jave code examples for showing how to use getItemAt() of the javax.swing.JComboBox class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: DatabaseExplorerInternalUIsTest.java   Source Code and License Vote up 6 votes
public void testComboboxWithDrivers() throws Exception {
    setUpDrivers();
    JComboBox combo = new JComboBox();
    DatabaseExplorerInternalUIs.connect(combo, JDBCDriverManager.getDefault());

    assertEquals(3, combo.getItemCount());
    JdbcUrl url = (JdbcUrl)combo.getItemAt(0);
    assertDriversEqual(driver2, url.getDriver());
    assertEquals(driver2.getClassName(), url.getClassName());
    assertEquals(driver2.getDisplayName(), url.getDisplayName());
    
    url = (JdbcUrl)combo.getItemAt(1);
    assertDriversEqual(driver1, url.getDriver());
    assertEquals(driver1.getClassName(), url.getClassName());
    assertEquals(driver1.getDisplayName(), url.getDisplayName());
}
 
Example 2
Project: incubator-netbeans   File: WizardUtils.java   Source Code and License Vote up 6 votes
/**
 * Searches LayerItemPresenter combobox by the item's display name.
 */
private static String searchLIPCategoryCombo(final JComboBox lpCombo, final String displayName) {
    String path = null;
    for (int i = 0; i < lpCombo.getItemCount(); i++) {
        Object item = lpCombo.getItemAt(i);
        if (!(item instanceof LayerItemPresenter)) {
            continue;
        }
        LayerItemPresenter presenter = (LayerItemPresenter) lpCombo.getItemAt(i);
        if (displayName.equals(presenter.getDisplayName())) {
            path = presenter.getFullPath();
            break;
        }
    }
    return path;
}
 
Example 3
Project: openjdk-jdk10   File: JComboBoxOperator.java   Source Code and License Vote up 6 votes
/**
 * Returns information about component.
 */
@Override
public Hashtable<String, Object> getDump() {
    Hashtable<String, Object> result = super.getDump();
    JComboBox<?> jComboBox = (JComboBox<?>) getSource();
    Object selectedItem = jComboBox.getSelectedItem();
    if (selectedItem != null) {
        result.put(TEXT_DPROP, selectedItem.toString());
    }
    int itemCount = jComboBox.getItemCount();
    String[] items = new String[itemCount];
    for (int i = 0; i < itemCount; i++) {
        if (jComboBox.getItemAt(i) != null) {
            items[i] = jComboBox.getItemAt(i).toString();
        }
    }
    addToDump(result, ITEM_PREFIX_DPROP, items);
    return result;
}
 
Example 4
Project: incubator-netbeans   File: SearchPatternController.java   Source Code and License Vote up 5 votes
/**
 * Bind Match Type option to a combo box.
 *
 * @param comboBox Combo box to control and display the match type. The
 * model of the combo box can contain only items of type {@link MatchType}.
 * {@link MatchType#LITERAL} and {@link MatchType#REGEXP} are mandatory in
 * the model.
 *
 * @since api.search/1.11
 */
public void bindMatchTypeComboBox(@NonNull final JComboBox comboBox) {
    Parameters.notNull("comboBox", comboBox);                       //NOI18N

    boolean regexpFound = false, literalFound = false;
    for (int i = 0; i < comboBox.getItemCount(); i++) {
        if (comboBox.getItemAt(i) == MatchType.LITERAL) {
            literalFound = true;
        } else if (comboBox.getItemAt(i) == MatchType.REGEXP) {
            regexpFound = true;
        } else if (!(comboBox.getItemAt(i) instanceof MatchType)) {
            throw new IllegalArgumentException("Model of the combo "//NOI18N
                    + "box can contain only MatchType items");      //NOI18N
        }
    }
    if (!(regexpFound && literalFound)) {
        throw new IllegalArgumentException(
                "At least MatchType.LITERAL and MatchType.REGEXP " //NOI18N
                + "must be contained in the combo box model.");     //NOI18N
    }
    if (matchTypeComboBox != null) {
        throw new IllegalStateException(
                "Already bound with option MATCH_TYPE");            //NOI18N
    }
    this.matchTypeComboBox = comboBox;
    comboBox.setEditable(false);
    setMatchType(this.matchType); //update match type, check it is supported
    comboBox.setSelectedItem(matchType);
    comboBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            setMatchType((MatchType) comboBox.getSelectedItem());
        }
    });
}
 
Example 5
Project: incubator-netbeans   File: PersistenceUnitPanel.java   Source Code and License Vote up 5 votes
/**
 * Sets the selected item in connection combo box.
 */
private void setSelectedConnection(){
    DatabaseConnection connection = ProviderUtil.getConnection(persistenceUnit);
    if (connection != null){
        jdbcComboBox.setSelectedItem(connection);
    } else {
        // custom connection (i.e. connection not registered in netbeans)
        Properties props = persistenceUnit.getProperties();
        if (props != null){
            Property[] properties = props.getProperty2();
            String url = null;
            ArrayList<Provider> providers = new ArrayList<Provider>();
            JComboBox activeCB = providerCombo.isVisible() ? providerCombo : libraryComboBox;
            for(int i=0; i<activeCB.getItemCount(); i++){
                Object obj = activeCB.getItemAt(i);
                if(obj instanceof Provider){
                    providers.add((Provider) obj);
                }
            }
            Provider provider = ProviderUtil.getProvider(persistenceUnit, providers.toArray(new Provider[]{}));
            for (int i = 0; i < properties.length; i++) {
                String key = properties[i].getName();
                if (provider.getJdbcUrl().equals(key)) {
                    url = properties[i].getValue();
                    break;
                }
            }
            if (url == null) {
                url = NbBundle.getMessage(PersistenceUnitPanel.class, "LBL_CustomConnection");//NOI18N
            }
            jdbcComboBox.addItem(url);
            jdbcComboBox.setSelectedItem(url);
        }
    }
}
 
Example 6
Project: incubator-netbeans   File: DatabaseExplorerInternalUIsTest.java   Source Code and License Vote up 5 votes
public void testComboboxWithDriversOfSameClass() throws Exception {
    removeDrivers();

    String name1 = "foo_driver";
    String name2 = "foo_driver2";

    String displayName1 = "FooDriver";
    String displayName2 = "FooDriver2";

    driver1 = JDBCDriver.create(name1, displayName1, "org.foo.FooDriver", new URL[0]);
    JDBCDriverManager.getDefault().addDriver(driver1);

    driver2 = JDBCDriver.create(name2, displayName2, "org.foo.FooDriver", new URL[0]);
    JDBCDriverManager.getDefault().addDriver(driver2);

    JComboBox combo = new JComboBox();
    DatabaseExplorerInternalUIs.connect(combo, JDBCDriverManager.getDefault());

    assertEquals(3, combo.getItemCount());

    JdbcUrl url = (JdbcUrl)combo.getItemAt(0);
    assertDriversEqual(driver1, url.getDriver());
    assertEquals(driver1.getClassName(), url.getClassName());
    assertEquals(driver1.getDisplayName(), url.getDisplayName());
    assertEquals(driver1.getName(), url.getName());

    url = (JdbcUrl)combo.getItemAt(1);
    assertDriversEqual(driver2, url.getDriver());
    assertEquals(driver2.getClassName(), url.getClassName());
    assertEquals(driver2.getDisplayName(), url.getDisplayName());
    assertEquals(driver2.getName(), url.getName());
}
 
Example 7
Project: incubator-netbeans   File: DatabaseExplorerInternalUIsTest.java   Source Code and License Vote up 5 votes
public void testComboBoxWithDriverClass() throws Exception {
    setUpDrivers();
    JComboBox combo = new JComboBox();
    DatabaseExplorerInternalUIs.connect(combo, JDBCDriverManager.getDefault(), "org.bar.BarDriver");

    assertEquals(1, combo.getItemCount());
    JdbcUrl url = (JdbcUrl)combo.getItemAt(0);
    assertDriversEqual(driver2, url.getDriver());
    assertEquals(driver2.getClassName(), url.getClassName());
    assertEquals(driver2.getDisplayName(), url.getDisplayName());
}
 
Example 8
Project: Equella   File: AppletGuiUtils.java   Source Code and License Vote up 5 votes
private static <T> int findIndexInCombo(JComboBox<T> combo, T obj)
{
	final int count = combo.getItemCount();
	for( int i = 0; i < count; i++ )
	{
		Object comboObject = combo.getItemAt(i);
		if( Objects.equals(comboObject, obj) )
		{
			return i;
		}
	}
	return -1;
}
 
Example 9
Project: freecol   File: SelectAmountDialog.java   Source Code and License Vote up 5 votes
/**
 * Verify the contents of the JComboBox.
 *
 * @return True if all is well.
 */
private boolean verifyWholeBox(JComboBox<Integer> box) {
    final int n = box.getItemCount();
    for (int i = 0; i < n; i++) {
        Integer v = box.getItemAt(i);
        if (v < 0 || v > available) return false;
    }
    return true;
}
 
Example 10
Project: FreeCol   File: SelectAmountDialog.java   Source Code and License Vote up 5 votes
/**
 * Verify the contents of the JComboBox.
 *
 * @return True if all is well.
 */
private boolean verifyWholeBox(JComboBox<Integer> box) {
    final int n = box.getItemCount();
    for (int i = 0; i < n; i++) {
        Integer v = box.getItemAt(i);
        if (v < 0 || v > available) return false;
    }
    return true;
}
 
Example 11
Project: Logisim   File: PrefOption.java   Source Code and License Vote up 5 votes
static <Option> void setSelected(JComboBox<Option> combo, Object value) {
	for (int i = combo.getItemCount() - 1; i >= 0; i--) {
		PrefOption opt = (PrefOption) combo.getItemAt(i);
		if (opt.getValue().equals(value)) {
			combo.setSelectedItem(opt);
			return;
		}
	}
	combo.setSelectedItem(combo.getItemAt(0));
}
 
Example 12
Project: Logisim   File: ComboOption.java   Source Code and License Vote up 5 votes
static void setSelected(JComboBox<?> combo, Object value) {
	for (int i = combo.getItemCount() - 1; i >= 0; i--) {
		ComboOption opt = (ComboOption) combo.getItemAt(i);
		if (opt.getValue().equals(value)) {
			combo.setSelectedItem(opt);
			return;
		}
	}
	combo.setSelectedItem(combo.getItemAt(0));
}