List of usage examples for javax.swing DefaultComboBoxModel getSize
public int getSize()
From source file:Main.java
public static void main(final String args[]) { final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>(); model.addElement("A"); model.addElement("C"); model.addElement("D"); model.addElement("A"); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComboBox<String> comboBox1 = new JComboBox<String>(model); comboBox1.setMaximumRowCount(5);/*from w w w . j a va 2s. c o m*/ comboBox1.setEditable(true); frame.add(comboBox1, BorderLayout.NORTH); JList<String> jlist = new JList<String>(model); JScrollPane scrollPane = new JScrollPane(jlist); frame.add(scrollPane, BorderLayout.CENTER); JButton button = new JButton("Add"); frame.add(button, BorderLayout.SOUTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { model.addElement("a"); System.out.println(model.getSize()); } }; button.addActionListener(actionListener); frame.setSize(300, 200); frame.setVisible(true); }
From source file:edu.ku.brc.specify.datamodel.busrules.PickListBusRules.java
/** * Returns the index in the model for the string value. * @param vcbx the combobox/* w w w.j a v a2 s . c o m*/ * @param value the value * @return the index in the model for the string value */ private int getIndexInModel(final ValComboBox vcbx, final String value) { DefaultComboBoxModel model = (DefaultComboBoxModel) vcbx.getComboBox().getModel(); for (int i = 0; i < model.getSize(); i++) { Object obj = model.getElementAt(i); if (obj instanceof DBTableInfo) { DBTableInfo ti = (DBTableInfo) obj; if (ti.getName().equals(value)) { return i; } } else if (obj instanceof DBFieldInfo) { DBFieldInfo fi = (DBFieldInfo) obj; if (fi.getName().equals(value)) { return i; } } else if (obj instanceof DataObjSwitchFormatter) { DataObjSwitchFormatter fmt = (DataObjSwitchFormatter) obj; if (fmt.getName().equals(value)) { return i; } } else if (obj.toString().equals(value)) { return i; } } return -1; }
From source file:com.mirth.connect.client.ui.panels.export.MessageExportPanel.java
public void setMessageWriterOptions(MessageWriterOptions options) { if (options.getContentType() == null) { contentComboBox.setSelectedItem(XML_EXPORT_FORMAT); } else {//from www . j a v a 2 s.c o m DefaultComboBoxModel model = (DefaultComboBoxModel) contentComboBox.getModel(); for (int i = 0; i < model.getSize(); i++) { Object element = model.getElementAt(i); if (element instanceof ExportFormat) { ExportFormat exportFormat = (ExportFormat) element; if (exportFormat.getContentType().equals(options.getContentType()) && exportFormat.isDestination() == options.isDestinationContent()) { contentComboBox.setSelectedItem(exportFormat); } } } } encryptCheckBox.setSelected(options.isEncrypt()); ArchiveFormat archiveFormat = ArchiveFormat.lookup(options.getArchiveFormat(), options.getCompressFormat()); if (archiveFormat == null) { compressComboBox.setSelectedItem(NO_COMPRESSION); } else { compressComboBox.setSelectedItem(archiveFormat); } compressComboBoxChanged(); rootPathTextField.setText(options.getRootFolder()); filePatternTextPane.setText(options.getFilePattern()); repaint(); }
From source file:com.mirth.connect.client.ui.panels.connectors.ResponseSettingsPanel.java
private void setSelectedItem(Object selectedItem) { DefaultComboBoxModel model = (DefaultComboBoxModel) responseComboBox.getModel(); if (selectedItem instanceof Entry) { /*/* w w w .j a v a 2 s . c o m*/ * If the selected item is an Entry and the key ("d#") is the same * as an Entry in the model, then they're "the same", and that entry * is selected. */ for (int i = 0; i <= model.getSize() - 1; i++) { if (model.getElementAt(i) instanceof Entry && ((Entry<String, String>) selectedItem).getKey() .equals(((Entry<String, String>) model.getElementAt(i)).getKey())) { responseComboBox.setSelectedIndex(i); return; } } } else if (model.getIndexOf(selectedItem) >= 0) { responseComboBox.setSelectedItem(selectedItem); return; } responseComboBox.setSelectedIndex(0); }
From source file:com.mirth.connect.client.ui.panels.connectors.SourceSettingsPanel.java
private void setSelectedItem(Object selectedItem) { DefaultComboBoxModel model = (DefaultComboBoxModel) responseComboBox.getModel(); if (selectedItem instanceof Entry) { /*//w ww .j a v a2 s . c o m * If the selected item is an Entry and the key ("d#") is the same as an Entry in the * model, then they're "the same", and that entry is selected. */ for (int i = 0; i <= model.getSize() - 1; i++) { if (model.getElementAt(i) instanceof Entry && ((Entry<String, String>) selectedItem).getKey() .equals(((Entry<String, String>) model.getElementAt(i)).getKey())) { responseComboBox.setSelectedIndex(i); return; } } } else if (model.getIndexOf(selectedItem) >= 0) { responseComboBox.setSelectedItem(selectedItem); return; } responseComboBox.setSelectedIndex(0); }
From source file:com.raddle.tools.MergeMain.java
private void selectLine(JList list, PropertyLine line) { DefaultComboBoxModel model = (DefaultComboBoxModel) list.getModel(); for (int i = 0; i < model.getSize(); i++) { PropertyLine mLine = (PropertyLine) model.getElementAt(i); if (mLine.getKey().equals(line.getKey())) { list.setSelectedValue(mLine, true); return; }//from w w w. ja va 2 s. co m } }
From source file:edu.ku.brc.specify.config.init.TaxonLoadSetupPanel.java
@Override public void doingNext() { super.doingNext(); DisciplineType disciplineType = (DisciplineType) properties.get("disciplineType"); if (disciplineType != null) { DefaultComboBoxModel model = new DefaultComboBoxModel(); Vector<TaxonFileDesc> taxonFileDescs = readTaxonLoadFiles(); if (taxonFileDescs != null) { for (TaxonFileDesc tfd : taxonFileDescs) { if (tfd.getDiscipline().equals(disciplineType.getName())) { model.addElement(tfd); }//from w w w.ja v a 2 s .c om } fileCBX.setModel(model); if (model.getSize() > 0) { fileCBX.setSelectedIndex(0); } if (firstTime) { firstTime = false; fileCBX.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { fileSelected(); } }); } fileSelected(); } else { fileCBX.setEnabled(false); preloadChk.setEnabled(false); } } }
From source file:edu.ku.brc.specify.tools.schemalocale.FieldItemPanel.java
/** * /*www . j av a 2 s .c o m*/ */ private void setAsDefFormatter() { Object item = formatCombo.getSelectedItem(); UIFieldFormatterIFace selected = null; if (item instanceof UIFieldFormatterIFace) { selected = (UIFieldFormatterIFace) item; } DefaultComboBoxModel model = (DefaultComboBoxModel) formatCombo.getModel(); for (int i = 1; i < model.getSize(); i++) { UIFieldFormatterIFace uif = (UIFieldFormatterIFace) model.getElementAt(i); uif.setDefault(uif == selected); } if (fieldInfo != null) { fieldInfo.setFormatter(selected); } }
From source file:edu.ku.brc.specify.tools.schemalocale.FieldItemPanel.java
/** * Fills the format Combobox with the available formatters. *//*from w w w . java2 s.c o m*/ protected void fillWebLinkBox() { if (webLinkCombo != null) { DefaultComboBoxModel wlModel = (DefaultComboBoxModel) webLinkCombo.getModel(); wlModel.removeAllElements(); //if (wlModel.getSize() == 0) { wlModel.addElement(webLinkDefNone); for (WebLinkDef wld : webLinkMgrCache.getWebLinkDefs(null)) { wlModel.addElement(wld); } } //wbLnkCombo.setEnabled(false); webLinkMoreBtn.setEnabled(true); //wbLnkCombo.setEnabled(false); int selInx = webLinkCombo.getModel().getSize() > 0 ? 0 : -1; LocalizableItemIFace fld = getSelectedFieldItem(); if (fld != null) { String webLinkName = fld.getWebLinkName(); if (StringUtils.isNotEmpty(webLinkName)) { DefaultComboBoxModel model = (DefaultComboBoxModel) webLinkCombo.getModel(); for (int i = 0; i < model.getSize(); i++) { WebLinkDef wld = (WebLinkDef) model.getElementAt(i); if (wld.getName().equals(webLinkName)) { selInx = i; break; } } } } webLinkCombo.setSelectedIndex(selInx); } }
From source file:gtu._work.ui.DirectoryCompareUI.java
private void initComponents() { DefaultTableModel dirCompareModel = getDefaultTableModel(); DefaultComboBoxModel extensionModel = new DefaultComboBoxModel(); extensionModel.addElement(EXTENSION_ALL); while (extensionNameComboBox.getModel().getSize() != extensionModel.getSize()) { extensionNameComboBox.setModel(extensionModel); System.out.println("reset extensionNameComboBox"); }/*from ww w .ja v a2 s . c o m*/ while (dirCompareTable.getModel().getRowCount() != dirCompareModel.getRowCount()) { dirCompareTable.setModel(dirCompareModel); System.out.println("reset dirCompareTable"); } searchText.setText(""); setTitle(""); compareStyleComboBox.setSelectedItem(EXTENSION_ALL); if (diffMergeChkBox != null) { for (JCheckBox chk : diffMergeChkBox) { chk.setSelected(true); } } }