Java JComboBox Model updateComboBoxModel(ComboBoxModel model, List values)

Here you can find the source of updateComboBoxModel(ComboBoxModel model, List values)

Description

update Combo Box Model

License

Apache License

Declaration

public static void updateComboBoxModel(ComboBoxModel model, List<?> values) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.List;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;

public class Main {
    public static void updateComboBoxModel(ComboBoxModel model, List<?> values) {
        DefaultComboBoxModel dcbm = (DefaultComboBoxModel) model;
        Object selected = dcbm.getSelectedItem();
        dcbm.removeAllElements();// ww  w.  j a v  a 2  s  . com
        for (Object e : values) {
            dcbm.addElement(e);
            if (e.equals(selected)) {
                dcbm.setSelectedItem(e);
            }
        }
    }
}

Related

  1. getComboModelList(ComboBoxModel model)
  2. getNewDefaultComboBoxModel(ArrayList itemsToStream)
  3. getSelectedItemfromModel(Object combo)
  4. hasDataChanged(List newDatasets, ComboBoxModel currentModel)
  5. modelToList(DefaultComboBoxModel model)
  6. updateComboBoxModel(final JComboBox aComboBox, final Vector aValues)