本文整理汇总了Java中javax.swing.JComboBox.getItemAt方法的典型用法代码示例。如果您正苦于以下问题:Java JComboBox.getItemAt方法的具体用法?Java JComboBox.getItemAt怎么用?Java JComboBox.getItemAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JComboBox
的用法示例。
在下文中一共展示了JComboBox.getItemAt方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testComboboxWithDrivers
import javax.swing.JComboBox; //导入方法依赖的package包/类
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());
}
示例2: searchLIPCategoryCombo
import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
* 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;
}
示例3: getDump
import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
* 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;
}
示例4: bindMatchTypeComboBox
import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
* 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());
}
});
}
示例5: setSelectedConnection
import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
* 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);
}
}
}
示例6: testComboboxWithDriversOfSameClass
import javax.swing.JComboBox; //导入方法依赖的package包/类
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());
}
示例7: testComboBoxWithDriverClass
import javax.swing.JComboBox; //导入方法依赖的package包/类
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());
}
示例8: findIndexInCombo
import javax.swing.JComboBox; //导入方法依赖的package包/类
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;
}
示例9: verifyWholeBox
import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
* 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;
}
示例10: setSelected
import javax.swing.JComboBox; //导入方法依赖的package包/类
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));
}
示例11: setSelected
import javax.swing.JComboBox; //导入方法依赖的package包/类
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));
}