javax.swing.JComboBox#getItemAt ( )源码实例Demo

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

源代码1 项目: ghidra   文件: MemSearchAsciiTest.java
@SuppressWarnings("unchecked")
private void setEncoding(Charset encoding) throws Exception {
	JComboBox<Charset> encodingOptions =
		(JComboBox<Charset>) findComponentByName(pane, "Encoding Options", false);

	// Makes encoding UTF_16 in case encoding is UTF_16BE or UTF_16LE
	// BE and LE are not choices in the combo box.
	if (encoding == StandardCharsets.UTF_16BE || encoding == StandardCharsets.UTF_16LE) {
		encoding = StandardCharsets.UTF_16;
	}

	for (int i = 0; i < encodingOptions.getItemCount(); i++) {
		if (encodingOptions.getItemAt(i) == encoding) {
			int index = i;
			runSwing(() -> encodingOptions.setSelectedIndex(index));
			break;
		}
	}
}
 
源代码2 项目: netbeans   文件: WizardUtils.java
/**
 * 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;
}
 
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());
}
 
源代码4 项目: openjdk-jdk9   文件: JComboBoxOperator.java
/**
 * 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;
}
 
源代码5 项目: jeddict   文件: DBConnectionUtil.java
/**
 * Load combobox with DB connection
 *
 * @param file
 * @param dbConComboBox
 */
public static void loadConnection(ModelerFile file, JComboBox dbConComboBox) {
    EntityMappings entityMappings = (EntityMappings) file.getDefinitionElement();
    Cache cache = entityMappings.getCache();
    DatabaseConnectionCache dbCache = cache.getDatabaseConnectionCache();

    DatabaseExplorerUIs.connect(dbConComboBox, ConnectionManager.getDefault());
    dbConComboBox.setToolTipText("Available Database Connection");

    for (int i = 0; i < dbConComboBox.getItemCount(); i++) {
        Object item = dbConComboBox.getItemAt(i);
        if (dbCache != null && item instanceof DatabaseConnection && ((DatabaseConnection) item).getDatabaseURL().equals(dbCache.getUrl())) {
            dbConComboBox.setSelectedIndex(i);
            break;
        }
    }
 
}
 
源代码6 项目: Shuffle-Move   文件: EditTeamService.java
private void updateKeybindComboBoxes() {
   Team curTeam = getCurrentTeam();
   for (String name : curTeam.getNames()) {
      ItemListener itemListener = nameToItemListenerMap.get(name);
      JComboBox<Character> box = nameToKeybindComboboxMap.get(name);
      box.removeItemListener(itemListener);
      Character prevSelected = box.getItemAt(box.getSelectedIndex());
      box.removeAllItems();
      Character curBinding = curTeam.getBinding(name);
      LinkedHashSet<Character> availableBindings = new LinkedHashSet<Character>(Arrays.asList(curBinding));
      availableBindings.addAll(myData.getAllAvailableBindingsFor(name, curTeam));
      for (Character ch : availableBindings) {
         if (ch != null) {
            box.addItem(ch);
         }
      }
      box.setSelectedItem(prevSelected);
      if (box.getSelectedIndex() < 0) {
         LOG.warning(getString(KEY_NO_BINDINGS));
      }
      box.addItemListener(itemListener);
   }
}
 
源代码7 项目: nextreports-designer   文件: DesignerTablePanel.java
public void updateGroupByItems(int dragRow, int dropRow) {
    MyRow drag_row = (MyRow) model.getObjectForRow(dragRow);
    JComboBox groupByComboDrag = (JComboBox) ((DefaultCellEditor) table.getCellEditor(dragRow, 6)).getComponent();

    MyRow drop_row = (MyRow) model.getObjectForRow(dropRow);
    JComboBox groupByComboDrop = (JComboBox) ((DefaultCellEditor) table.getCellEditor(dropRow, 6)).getComponent();

    String sDrag = (String) groupByComboDrag.getItemAt(0);
    String sDrop = (String) groupByComboDrop.getItemAt(0);

    if ("".equals(sDrag) && !sDrag.equals(sDrop)) {
        groupByComboDrop.insertItemAt("", 0);
        groupByComboDrag.removeItem("");
    }

    if ("".equals(sDrop) && !sDrop.equals(sDrag)) {
        groupByComboDrag.insertItemAt("", 0);
        groupByComboDrop.removeItem("");
    }
}
 
源代码8 项目: JPPF   文件: ConnectionFailedTask.java
/**
 * Perform the task.
 */
@Override
public void run() {
  synchronized(statsHandler) {
    if (statsHandler.dataHolderMap.get(driver.getUuid()) != null) {
      final ConnectionDataHolder cdh = statsHandler.dataHolderMap.remove(driver.getUuid());
      if (cdh != null) cdh.close();
    }
  }
  JComboBox<?> box = null;
  while (statsHandler.getClientHandler().getServerListOption() == null) goToSleep(50L);
  final JPPFClientConnection c = driver.getConnection();
  synchronized(statsHandler) {
    if (debugEnabled) log.debug("removing client connection " + c.getName() + " from driver combo box");
    box = ((ComboBoxOption) statsHandler.getClientHandler().getServerListOption()).getComboBox();
    final int count = box.getItemCount();
    int idx = -1;
    for (int i=0; i<count; i++) {
      final Object o = box.getItemAt(i);
      if (c.equals(o)) {
        box.removeItemAt(i);
        idx = i;
        break;
      }
    }
    if ((idx >= 0) && (box.getItemCount() > 0)) {
      if ((statsHandler.getClientHandler().currentDriver == null) || c.equals(statsHandler.getClientHandler().currentDriver.getConnection())) {
        final int n = Math.min(idx, box.getItemCount()-1);
        final TopologyDriver item = (TopologyDriver) box.getItemAt(n);
        statsHandler.getClientHandler().currentDriver = item;
        box.setSelectedItem(item);
      }
    }
  }
}
 
源代码9 项目: netbeans   文件: PersistenceUnitPanel.java
/**
 * 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);
        }
    }
}
 
源代码10 项目: netbeans   文件: SearchPatternController.java
/**
 * 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());
        }
    });
}
 
源代码11 项目: netbeans   文件: DatabaseExplorerInternalUIsTest.java
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());
}
 
源代码12 项目: netbeans   文件: DatabaseExplorerInternalUIsTest.java
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());
}
 
源代码13 项目: freecol   文件: SelectAmountDialog.java
/**
 * Verify the contents of the JComboBox.
 *
 * @param box The {@code JComboBox} to verify.
 * @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;
}
 
源代码14 项目: Logisim   文件: PrefOption.java
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));
}
 
源代码15 项目: Logisim   文件: ComboOption.java
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));
}
 
源代码16 项目: gcs   文件: UIUtilities.java
/**
 * Since JComboBox.getSelectedItem() returns a plain Object, this allows us to get the
 * appropriate type of object instead.
 */
public static <E> E getTypedSelectedItemFromCombo(JComboBox<E> combo) {
    int index = combo.getSelectedIndex();
    return index == -1 ? null : combo.getItemAt(index);
}