List of utility methods to do JComboBox Item
void | addFirstItem(JComboBox Checks if the item is in the combobox. int idx = -1; DefaultComboBoxModel<T> model = (DefaultComboBoxModel<T>) combobox.getModel(); for (int i = 0; i < model.getSize(); i++) { T t = model.getElementAt(i); if (Objects.equals(t, item)) { idx = i; break; model.insertElementAt(item, 0); if (idx >= 0) { model.removeElementAt(idx + 1); |
void | addHeadersaveFileTypeItemsTo(JComboBox add Headersave File Type Items To for (String s : headersaveFileTypeItems) {
combo.addItem(s);
|
void | addItems(JComboBox comboBox, Iterable items) add Items for (Object item : items) {
comboBox.addItem(item);
|
boolean | contains(final JComboBox contains final Set<Object> items = new HashSet<>(); for (int i = 0; i < comboBox.getItemCount(); i++) { items.add(comboBox.getItemAt(i)); return items.contains(item); |
void | fillCombo(JComboBox comboBox, Collection items) fill Combo comboBox.setModel(new DefaultComboBoxModel(items.toArray()));
|
int | findComboBoxItemForString(final JComboBox box, final String searchString) DOCUMENT ME! if ((box != null) && (searchString != null)) { final ComboBoxModel model = box.getModel(); if (model != null) { for (int i = model.getSize(); --i >= 0;) { if (searchString.equals(String.valueOf(model.getElementAt(i)))) { return i; return -1; |
int | getDataIndexFromComboBox(JComboBox cbb, String dta) get Data Index From Combo Box for (int i = 0; i < ((DefaultComboBoxModel) cbb.getModel()).getSize(); i++) { String data = (String) ((DefaultComboBoxModel) cbb.getModel()).getElementAt(i); if (data.equals(dta)) return i; return -1; |
List | getItems(JComboBox box) return the list of items held by the combo box. List l = new ArrayList(); for (int i = 0; i < box.getItemCount(); i++) { l.add(box.getItemAt(i)); return l; |
List | getItems(JComboBox comboBox) get Items List result = new ArrayList(); for (int i = 0; i < comboBox.getItemCount(); i++) { Object element = comboBox.getItemAt(i); result.add(element); return result; |
void | insertIntoCombo(JComboBox combo, Object item) Insert the given item into the combo box, and set it as first selected item. MutableComboBoxModel model = (MutableComboBoxModel) combo.getModel(); if (model.getSize() == 0) { model.insertElementAt(item, 0); return; Object o = model.getElementAt(0); if (o.equals(item)) { return; ... |