List of usage examples for javax.swing JComboBox getItemCount
@BeanProperty(bound = false) public int getItemCount()
From source file:us.daveread.basicquery.BasicQuery.java
/** * Checks whether an input (query or connect string) is already in its * associated combo box. If not, the new information is added to the combo * list//from w w w . j a va 2 s .co m * * @param combo * JComboBox which has a list of the query statements or connect * strings. */ private void checkForNewString(JComboBox combo) { // String newString, foundString; Object newValue; int checkDups, matchAt; boolean match; // boolean newCommented, foundCommented; // newCommented = foundCommented = false; matchAt = -1; if (combo == querySelection) { newValue = new Query(queryText.getText(), whichModeValue()); // newString = queryText.getText(); // newString = newString.replace('\n', ' '); } else { // newString = (String)combo.getEditor().getItem(); newValue = combo.getEditor().getItem(); } // if (newString.startsWith(COMMENT_PREFIX)) { // newCommented = true; // newString = newString.substring(2); // } // if (newString.trim().length() > 0) { if (newValue.toString().length() > 0) { match = false; for (checkDups = 0; checkDups < combo.getItemCount() && !match; ++checkDups) { // if (combo == querySelection) { // foundString = ((Query)combo.getItemAt(checkDups)).getSQL(); // } else { // foundString = ((String)combo.getItemAt(checkDups)); // } // if (foundString.startsWith(COMMENT_PREFIX)) { // foundString = foundString.substring(2); // foundCommented = true; // } else { // foundCommented = false; // } // if (newString.equals(foundString)) { if (newValue.equals(combo.getItemAt(checkDups))) { match = true; if (combo == querySelection) { ((Query) combo.getItemAt(checkDups)).setMode(whichModeValue()); } combo.setSelectedIndex(checkDups); matchAt = checkDups; } } // if (newCommented) { // newString = COMMENT_PREFIX + newString; // } if (!match) { addToCombo(combo, newValue); if (combo == querySelection) { // addToCombo(combo, new Query(newString, whichModeValue())); combo.setSelectedIndex(combo.getModel().getSize() - 1); matchAt = combo.getSelectedIndex(); } } // if (foundCommented != newCommented) { // if (combo == querySelection) { // replaceInCombo(combo, matchAt, // new Query(newString, whichModeValue())); // } else { // replaceInCombo(combo, matchAt, newString); // } // } if (combo == querySelection) { if (((Query) newValue).isCommented() != ((Query) combo.getSelectedItem()).isCommented()) { replaceInCombo(combo, matchAt, newValue); } } } }