List of utility methods to do JComboBox Item
List | items(JComboBox comboBox) items ArrayList items = new ArrayList(); for (int i = 0; i < comboBox.getItemCount(); i++) { items.add(comboBox.getItemAt(i)); return items; |
void | loadCombo(JComboBox cmb, List data) load Combo cmb.addItem(" "); if (data != null) { Iterator it = data.iterator(); while (it.hasNext()) { cmb.addItem(it.next()); |
void | loadInstances(JComboBox target, Class> source, Class> limit, Object defaultItem) load Instances Class<?>[] clss = source.getClasses(); for (Class<?> cls : clss) { try { if (!limit.isAssignableFrom(cls)) { continue; if (cls.isInterface()) { continue; ... |
void | loadStaticItems(JComboBox target, Class source, Class> limit, String defaultItem) load Static Items Field[] fields = source.getFields(); for (Field f : fields) { try { if (!java.lang.reflect.Modifier.isStatic(f.getModifiers())) { continue; Object v = f.get(null); if (v == null) { ... |
JComboBox | makeComboBox(Object[] items) Creates a combo box that remains one line in height. return new JComboBox(items) { public Dimension getMaximumSize() { Dimension pref = getPreferredSize(); Dimension max = super.getMaximumSize(); return new Dimension(max.width, pref.height); }; |
void | replaceComboContents(JComboBox cb, String[] items) replace Combo Contents ActionListener[] listeners = cb.getActionListeners(); for (int i = 0; i < listeners.length; i++) cb.removeActionListener(listeners[i]); if (cb.getItemCount() > 0) cb.removeAllItems(); for (int i = 0; i < items.length; i++) { cb.addItem(items[i]); for (int i = 0; i < listeners.length; i++) cb.addActionListener(listeners[i]); |
void | replaceComboItems(JComboBox combo, Vector items) Replace all items in a JComboBox (What am I missing in the published API?) combo.removeAllItems(); Iterator scit = items.iterator(); while (scit.hasNext()) { combo.addItem(scit.next()); return; |
void | selJComboBoxItem(Properties properties, JComboBox combo, Vector> namVec, String name) Sets the selection of the JComboBox to the Object 'name' from the list in namVec. int idx = namVec.indexOf(name);
combo.setSelectedIndex(idx);
combo.updateUI();
|
void | selJComboBoxItem(Properties properties, JComboBox> combo, Vector> namVec, String name) Sets the selection of the JComboBox to the Object 'name' from the list in namVec. int idx = namVec.indexOf(name);
combo.setSelectedIndex(idx);
combo.updateUI();
|
void | setListData(JComboBox box, Object[] items) Procedure to set the list of items in a ComboBox box.removeAllItems(); if (items != null) { for (int i = 0; i < items.length; i++) { box.addItem(items[i]); |