List of usage examples for javax.swing ComboBoxModel getElementAt
E getElementAt(int index);
From source file:Main.java
/** * @param comboBox/*from w w w . jav a 2s . c o m*/ * @param value * @return if the comboBox contains the specified value */ public static boolean containsValue(JComboBox comboBox, String value) { ComboBoxModel model = comboBox.getModel(); int size = model.getSize(); for (int i = 0; i < size; i++) { Object element = model.getElementAt(i); if (element.equals(value)) { return true; } } return false; }
From source file:org.jdal.swing.form.FormUtils.java
/** * Return a List of Objects from a ComboBoxModel * @param model ComboBoxModel/*from w w w .ja va 2 s. co m*/ * @return a list of Objects with ComboBoxModel items */ public static List<Object> getComboModelList(ComboBoxModel<?> model) { ArrayList<Object> list = new ArrayList<Object>(); for (int i = 0; i < model.getSize(); i++) { list.add(model.getElementAt(i)); } return list; }
From source file:Main.java
public int selectionForKey(char aKey, ComboBoxModel model) { int selIx = 01; Object sel = model.getSelectedItem(); if (sel != null) { for (int i = 0; i < model.getSize(); i++) { if (sel.equals(model.getElementAt(i))) { selIx = i;//from w w w . j av a 2s .c o m break; } } } long curTime = System.currentTimeMillis(); if (curTime - lastKeyTime < 300) { pattern += ("" + aKey).toLowerCase(); } else { pattern = ("" + aKey).toLowerCase(); } lastKeyTime = curTime; for (int i = selIx + 1; i < model.getSize(); i++) { String s = model.getElementAt(i).toString().toLowerCase(); if (s.startsWith(pattern)) { return i; } } for (int i = 0; i < selIx; i++) { if (model.getElementAt(i) != null) { String s = model.getElementAt(i).toString().toLowerCase(); if (s.startsWith(pattern)) { return i; } } } return -1; }
From source file:ja.lingo.application.gui.main.settings.appearance.AppearanceGui.java
private void setSelectedFontSize(int fontSize) { ComboBoxModel model = fontSizeComboBox.getModel(); for (int i = 0; i < model.getSize(); i++) { Integer value = (Integer) model.getElementAt(i); if (value.equals(fontSize)) { fontSizeComboBox.setSelectedItem(value); return; }/* ww w .j ava2s. com*/ } // TODO refactoring needed: move out default size + allowed sizes LOG.warn("Incorrect font size: " + fontSize + ", setting size to default"); setSelectedFontSize(DEFAULT_FONT_SIZE); // NOTE potential recursion appearance on re-factoring }
From source file:ja.lingo.application.gui.main.settings.appearance.AppearanceGui.java
private void setSelectedFontFace(String fontFace) { ComboBoxModel model = fontFaceComboBox.getModel(); for (int i = 0; i < model.getSize(); i++) { String value = (String) model.getElementAt(i); System.out.println(value); System.out.println(fontFace); if (value.equals(fontFace)) { fontFaceComboBox.setSelectedItem(value); return; }//from w w w .jav a 2 s . co m } // TODO refactoring needed: move out default size + allowed sizes LOG.warn("Incorrect font face: " + fontFace + ", setting font to default"); setSelectedFontFace("SansSerif"); // NOTE potential recursion appearance on re-factoring }
From source file:au.org.ala.delta.intkey.ui.WebSearchDialog.java
private void loadSearchEngines(File file, JComboBox cmb) { List<SearchEngineDescriptor> engines = new ArrayList<WebSearchDialog.SearchEngineDescriptor>(); try {/*from w ww . ja v a 2 s .com*/ List<String> lines = FileUtils.readLines(file); for (String line : lines) { SearchEngineDescriptor desc = parseSearchEngineDescriptor(line); if (desc != null) { engines.add(desc); } else { Logger.log("Could not parse search engine descriptor: " + line); } } ComboBoxModel model = new DefaultComboBoxModel(engines.toArray()); cmb.setModel(model); if (model.getSize() > 0) { model.setSelectedItem(model.getElementAt(0)); } } catch (IOException ioex) { throw new RuntimeException(ioex); } }
From source file:com.anrisoftware.prefdialog.fields.historycombobox.HistoryComboBoxField.java
private void removeHistory(int index0, int index1) { ComboBoxModel<?> model = getComponent().getModel(); for (int i = index0; i <= index1; i++) { Object element = model.getElementAt(i); history.remove(element);/*from w w w . jav a 2 s.c om*/ } }
From source file:com.anrisoftware.prefdialog.fields.historycombobox.HistoryComboBoxField.java
@SuppressWarnings("unchecked") private void insertHistory(int index0, int index1) { ComboBoxModel<?> model = getComponent().getModel(); for (int i = index0; i <= index1; i++) { Object element = model.getElementAt(i); history.add(element);/*ww w. j av a2 s . c om*/ } }
From source file:com.anrisoftware.prefdialog.fields.historycombobox.HistoryComboBoxField.java
@SuppressWarnings("unchecked") private void replaceHistory(int index0, int index1) { ComboBoxModel<?> model = getComponent().getModel(); for (int i = index0; i <= index1; i++) { Object element = model.getElementAt(i); history.remove(element);// ww w. java 2s .c om history.add(element); } }
From source file:de.fhg.iais.asc.ui.parts.HarvesterPanel.java
private boolean setSelectedString(JComboBox comboBox, String stringToSelect) { final ComboBoxModel model = comboBox.getModel(); int size = model.getSize(); for (int index = 0; index < size; index++) { if (model.getElementAt(index).toString().equals(stringToSelect)) { comboBox.setSelectedIndex(index); return true; }/*from w w w. j a va 2 s . com*/ } return false; }