List of usage examples for javax.swing JComboBox removeAllItems
public void removeAllItems()
From source file:org.smart.migrate.ui.UpdateRelatePKDialog.java
private void initTables(JComboBox comboBox) { comboBox.removeAllItems(); List<String> tables = migratePlan.getTargetTableNames(); for (String table : tables) { comboBox.addItem(table);/* w w w. j a va2 s .c o m*/ } }
From source file:org.smart.migrate.ui.UpdateRelatePKDialog.java
private void initFields(JComboBox comboBox, String table) { comboBox.removeAllItems(); List<Field> fields = getMetaDao().getFieldsOfTable(getConnection(), table); for (Field field : fields) { comboBox.addItem(field.getName()); }/*from w w w .java2 s . com*/ }
From source file:org.ut.biolab.medsavant.client.filter.TagFilterView.java
private static void updateTagValues(String tagName, JComboBox tagValueCB) { tagValueCB.removeAllItems(); if (tagName != null) { List<String> values; try {/*from w ww . j a va 2 s . c o m*/ values = MedSavantClient.VariantManager.getValuesForTagName(LoginController.getSessionID(), tagName); for (String val : values) { tagValueCB.addItem(val); } } catch (Exception ex) { ClientMiscUtils.reportError("Error updating tag values: %s", ex); } } tagValueCB.updateUI(); }
From source file:org.yccheok.jstock.gui.EnumComboBoxPropertyEditor.java
public void setValue(Object value) { JComboBox box = (JComboBox) editor; // We need to remove the previous items. This is because if a // property panel is having more than 1 enum type property, we // may display wrong type of enum. box.removeAllItems(); if (box.getItemCount() == 0) { try {//from w w w. j a v a2 s . co m java.lang.reflect.Method m = value.getClass().getMethod("values"); Enum[] array = (Enum[]) m.invoke(null); this.setAvailableValues(array); } catch (java.lang.NoSuchMethodException exp) { log.error(null, exp); } catch (java.lang.IllegalAccessException exp) { log.error(null, exp); } catch (java.lang.reflect.InvocationTargetException exp) { log.error(null, exp); } } super.setValue(value); }
From source file:ro.nextreports.designer.querybuilder.RuntimeParametersPanel.java
@SuppressWarnings("unchecked") private void initParameterValue(JComponent component, Object value, String paramName, List<Serializable> defaultValues) { if (value == null) { return;/* ww w . j a va2 s.c om*/ } if (component instanceof JTextField) { ((JTextField) component).setText(value.toString()); } else if (component instanceof JComboBox) { JComboBox combo = ((JComboBox) component); List<IdName> values = (List<IdName>) value; combo.removeAllItems(); combo.addItem("-- " + I18NSupport.getString("parameter.value.select") + " --"); for (int j = 0, len = values.size(); j < len; j++) { combo.addItem(values.get(j)); } Object old = parametersValues.get(paramName); if (old != null) { combo.setSelectedItem(old); } else if ((defaultValues != null) && (defaultValues.size() > 0)) { Serializable id = defaultValues.get(0); if (id instanceof IdName) { id = ((IdName) id).getId(); } combo.setSelectedItem(findIdName(combo.getModel(), id)); } } else if (component instanceof ListSelectionPanel) { ListSelectionPanel lsp = (ListSelectionPanel) component; DefaultListModel model = new DefaultListModel(); if (value != null) { List<IdName> values = (List<IdName>) value; for (int j = 0, len = values.size(); j < len; j++) { model.addElement(values.get(j)); } } ArrayList srcList = new ArrayList(Arrays.asList(model.toArray())); Object old = parametersValues.get(paramName); Object[] selected = new Object[0]; if (old != null) { selected = (Object[]) old; } else if ((defaultValues != null) && (defaultValues.size() > 0)) { selected = new Object[defaultValues.size()]; for (int k = 0, len = selected.length; k < len; k++) { Serializable id = defaultValues.get(k); if (id instanceof IdName) { id = ((IdName) id).getId(); } IdName in = findIdName(srcList, id); selected[k] = in; } } List dstList = Arrays.asList(selected); if (!srcList.containsAll(dstList)) { dstList = new ArrayList(); parametersValues.put(paramName, null); } else { srcList.removeAll(dstList); } if ((dstList.size() == 1) && ParameterUtil.NULL.equals(dstList.get(0))) { dstList = new ArrayList(); } lsp.setLists(srcList, dstList); } else if (component instanceof ListAddPanel) { ListAddPanel lap = (ListAddPanel) component; DefaultListModel model = new DefaultListModel(); if (value != null) { List<Object> values = (List<Object>) value; for (int j = 0, len = values.size(); j < len; j++) { model.addElement(values.get(j)); } } ArrayList srcList = new ArrayList(Arrays.asList(model.toArray())); Object old = parametersValues.get(paramName); Object[] selected = new Object[0]; if (old != null) { selected = (Object[]) old; } else if ((defaultValues != null) && (defaultValues.size() > 0)) { selected = new Object[defaultValues.size()]; for (int k = 0, len = selected.length; k < len; k++) { Serializable id = defaultValues.get(k); if (id instanceof IdName) { id = ((IdName) id).getId(); } selected[k] = id; } } List dstList = Arrays.asList(selected); if (!srcList.containsAll(dstList)) { dstList = new ArrayList(); parametersValues.put(paramName, null); } else { srcList.removeAll(dstList); } if ((dstList.size() == 1) && ParameterUtil.NULL.equals(dstList.get(0))) { dstList = new ArrayList(); } lap.setElements(dstList); } else if (component instanceof JDateTimePicker) { ((JDateTimePicker) component).setDate((Date) value); } else if (component instanceof JXDatePicker) { ((JXDatePicker) component).setDate((Date) value); } else if (component instanceof JCheckBox) { ((JCheckBox) component).setSelected((Boolean) value); } }
From source file:shuffle.fwk.service.teams.EditTeamService.java
private void updateKeybindComboBoxes() { Team curTeam = getCurrentTeam();// w w w . ja v a 2 s. co m for (String name : curTeam.getNames()) { ItemListener itemListener = nameToItemListenerMap.get(name); JComboBox<Character> box = nameToKeybindComboboxMap.get(name); box.removeItemListener(itemListener); Character prevSelected = box.getItemAt(box.getSelectedIndex()); box.removeAllItems(); Character curBinding = curTeam.getBinding(name); LinkedHashSet<Character> availableBindings = new LinkedHashSet<Character>(Arrays.asList(curBinding)); availableBindings.addAll(myData.getAllAvailableBindingsFor(name, curTeam)); for (Character ch : availableBindings) { if (ch != null) { box.addItem(ch); } } box.setSelectedItem(prevSelected); if (box.getSelectedIndex() < 0) { LOG.warning(getString(KEY_NO_BINDINGS)); } box.addItemListener(itemListener); } }
From source file:storybook.model.EntityUtil.java
@SuppressWarnings("unchecked") public static void fillAutoCombo(MainFrame mainFrame, AutoCompleteComboBox autoCombo, AbstractEntityHandler entityHandler, String text, String methodName) { try {/* w ww . j a v a 2 s. co m*/ JComboBox combo = autoCombo.getJComboBox(); combo.removeAllItems(); BookModel model = mainFrame.getBookModel(); Session session = model.beginTransaction(); SbGenericDAOImpl<?, ?> dao = entityHandler.createDAO(); dao.setSession(session); Method m = dao.getClass().getMethod(methodName, (Class<?>[]) null); List<Object> items = (List<Object>) m.invoke(dao); model.commit(); for (Object item : items) { if (item == null || ((item instanceof String) && (((String) item).isEmpty()))) { continue; } combo.addItem(item); } combo.addItem(""); combo.getModel().setSelectedItem(text); combo.revalidate(); } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { SbApp.error("EntityUtil.copyEntityProperties()", e); } }
From source file:storybook.model.EntityUtil.java
@SuppressWarnings("unchecked") public static void fillEntityCombo(MainFrame mainFrame, JComboBox combo, AbstractEntityHandler entityHandler, AbstractEntity entity, boolean isNew, boolean addEmptyItem) { combo.removeAllItems(); ListCellRenderer renderer = entityHandler.getListCellRenderer(); if (renderer != null) { combo.setRenderer(renderer);//from www . ja v a2 s.c o m } int i = 0; if (addEmptyItem) { ++i; combo.addItem(""); } BookModel model = mainFrame.getBookModel(); Session session = model.beginTransaction(); SbGenericDAOImpl<?, ?> dao = entityHandler.createDAO(); dao.setSession(session); @SuppressWarnings("unchecked") List<AbstractEntity> entities = (List<AbstractEntity>) dao.findAll(); for (AbstractEntity entity2 : entities) { session.refresh(entity2); combo.addItem(entity2); if (entity != null) { if (entity.getId().equals(entity2.getId())) // don't use combo.setSelectedItem(entity) here // leads to a "no session" exception for tag links { combo.setSelectedIndex(i); } } ++i; } combo.revalidate(); model.commit(); }
From source file:uk.chromis.pos.imports.JPanelCSVImport.java
private void jComboBoxFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jComboBoxFocusGained JComboBox myJComboBox = ((javax.swing.JComboBox) (evt.getComponent())); myJComboBox.removeAllItems(); int i = 1;//from www . j a va2s. c o m myJComboBox.addItem(""); while (i < Headers.size()) { if (!isEntryInUse(Headers.get(i))) { myJComboBox.addItem(Headers.get(i)); } ++i; } jComboCategory.addItem(category_disable_text); }