Author: tchemit Date: 2008-12-14 19:31:48 +0000 (Sun, 14 Dec 2008) New Revision: 1082 Modified: lutinjaxx/trunk/jaxx-core/changelog.txt lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/swing/Utils.java Log: add jaww.runtime.swing.Utils.fillComboBox to fill a combobox model from a collection Modified: lutinjaxx/trunk/jaxx-core/changelog.txt =================================================================== --- lutinjaxx/trunk/jaxx-core/changelog.txt 2008-12-14 18:42:16 UTC (rev 1081) +++ lutinjaxx/trunk/jaxx-core/changelog.txt 2008-12-14 19:31:48 UTC (rev 1082) @@ -1,5 +1,6 @@ 0.8 ??? 2009???? - * 20081214 [chemit] - add addSourcesToClassPath property to add sources directories in class-path + * 20081214 [chemit] - add jaww.runtime.swing.Utils.fillComboBox to fill a combobox model from a collection + - add addSourcesToClassPath property to add sources directories in class-path - improve classloader managment - keep in DataSource objetCode - fix bug when processDataBinding on a null objectCode Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/swing/Utils.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/swing/Utils.java 2008-12-14 18:42:16 UTC (rev 1081) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/swing/Utils.java 2008-12-14 19:31:48 UTC (rev 1082) @@ -4,11 +4,14 @@ */ package jaxx.runtime.swing; +import javax.swing.DefaultComboBoxModel; import javax.swing.ImageIcon; +import javax.swing.JComboBox; import javax.swing.SwingUtilities; import javax.swing.text.AbstractDocument; import javax.swing.text.JTextComponent; import java.lang.reflect.Field; +import java.util.Collection; public class Utils { private static Field numReaders; @@ -34,7 +37,7 @@ return; } - if (((Integer) numReaders.get(document)).intValue() > 0) { + if ((Integer) numReaders.get(document) > 0) { SwingUtilities.invokeLater(new Runnable() { public void run() { if (!c.getText().equals(text)) { @@ -78,4 +81,29 @@ return createImageIcon("i18n/" + name + ".png"); } + /** + * Fill a combo box model with some datas, and select after all the given object + * + * @param combo the combo to fill + * @param data data ot inject in combo + * @param select the object to select in combo after reflling his model + */ + public static void fillComboBox(JComboBox combo, Collection<?> data, Object select) { + if (!(combo.getModel() instanceof DefaultComboBoxModel)) { + throw new IllegalArgumentException("this method need a DefaultComboBoxModel for this model but was " + combo.getModel().getClass()); + } + DefaultComboBoxModel model = (DefaultComboBoxModel) combo.getModel(); + // evince the model + model.removeListDataListener(combo); + model.removeAllElements(); + for (Object o : data) { + model.addElement(o); + } + // attach the model + model.addListDataListener(combo); + if (select != null) { + model.setSelectedItem(select); + } + } + }