Example usage for javax.swing JComboBox removeAllItems

List of usage examples for javax.swing JComboBox removeAllItems

Introduction

In this page you can find the example usage for javax.swing JComboBox removeAllItems.

Prototype

public void removeAllItems() 

Source Link

Document

Removes all items from the item list.

Usage

From source file:com.mirth.connect.client.ui.Frame.java

/**
 * Creates all the items in the combo box for the connectors.
 * /*  w w  w .ja  va 2  s.co m*/
 * This method is called from each connector.
 */
public void setupCharsetEncodingForConnector(javax.swing.JComboBox charsetEncodingCombobox) {
    if (this.availableCharsetEncodings == null) {
        this.setCharsetEncodings();
    }
    if (this.availableCharsetEncodings == null) {
        logger.error("Error, the are no encodings detected.");
        return;
    }
    charsetEncodingCombobox.removeAllItems();
    for (int i = 0; i < this.availableCharsetEncodings.size(); i++) {
        charsetEncodingCombobox.addItem(this.availableCharsetEncodings.get(i));
    }
}

From source file:npm.modules.java

public boolean listtocombox(Document doc, JComboBox boxname, String parentnodename, String nodename) {
    boxname.removeAllItems();
    NodeList nlist = doc.getElementsByTagName(parentnodename);
    for (int temp = 0; temp < nlist.getLength(); temp++) {
        //System.out.println(nodename +"---"+temp);
        Node nNode = nlist.item(temp);
        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
            Element eElement = (Element) nNode;
            boxname.addItem(eElement.getElementsByTagName(nodename).item(0).getTextContent());
        }//from   ww w.  j a  va 2 s .co  m
    }
    return true;
}

From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataElementCellEditor.java

public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected,
        final int rowIndex, final int vColIndex) {
    // 'value' is value contained in the cell located at (rowIndex,
    // vColIndex)

    final MetaDataTableModel model = (MetaDataTableModel) table.getModel();
    final IMetaDataTypeExtended type = model.getRow(rowIndex);
    final int maximumLength = type.getMaximumLength();
    switch (type.getDataType()) {
    case Date:
        cal.setFormats(DATE_FORMAT);/*from  w w w  .j a va 2 s. co m*/
        component = componentDatePicker;
        ((JXDatePicker) component).setDate(parseDate((String) value));
        break;
    case MultiSelect:
        component = componentCombo;
        final JComboBox box = (JComboBox) component;
        box.removeAllItems();
        box.addItem(new MetaDataListValues("", "", 0));
        int itemNo = 1;
        for (MetaDataListValues listValue : type.getListItems()) {
            box.addItem(listValue);
            if (listValue.getValue().equals(value)) {
                box.setSelectedIndex(itemNo);
            }
            itemNo++;
        }
        ((JComboBox) component).setSelectedItem((String) value);
        break;
    case Boolean:
        component = componentCheck;
        final boolean boolValue = Boolean.parseBoolean((String) value);
        ((JCheckBox) component).setSelected(boolValue);
        break;
    case Integer:
        component = componentWholeNumber;
        ((WholeNumberField) component).setText((String) value);
        break;
    case RealNumber:
        component = componentDecimal;
        ((DecimalNumberField) component).setText((String) value);
        break;
    case Text:
    default:
        component = componentText;
        ((MaxLengthTextField) component).setMaximumLength(maximumLength);
        if (value == null) {
            ((MaxLengthTextField) component).setText("");
        } else {
            ((MaxLengthTextField) component).setText((String) value);
        }
    }
    if (theStandardFont != null) {
        component.setFont(theStandardFont);
    }
    return component;
}

From source file:org.netbeans.jpa.modeler.specification.model.util.JPAModelerUtil.java

public static void initEntityModel(javax.swing.JComboBox entityComboBox, EntityMappings entityMappings) {
    entityComboBox.removeAllItems();
    entityComboBox.addItem(new ComboBoxValue(null, ""));
    entityMappings.getEntity().stream().forEach((entity) -> {
        entityComboBox.addItem(new ComboBoxValue(entity, entity.getClazz()));
    });//from   w  ww.j  a v a  2s . c o m
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.LocationDialog.java

/**
 * Populates the JComboBox with the items provided adding hover tooltips,
 * selecting the specified item and attaching the listener.
 * //from  w ww  . j av  a  2 s. c  om
 * @param comboBox The JComboBox to populate
 * @param listItems The items to populate the box with
 * @param select The item to select in the JComboBox
 * @param itemListener An item listener to add for the JComboBox
 */
private void displayItems(JComboBox comboBox, List<DataNode> listItems, DataNode select,
        ItemListener itemListener) {
    if (comboBox == null || listItems == null)
        return;
    //Only add the item the user can actually select
    if (itemListener != null)
        comboBox.removeItemListener(itemListener);
    comboBox.removeAllItems();

    List<String> tooltips = new ArrayList<String>(listItems.size());
    List<String> lines;
    ExperimenterData exp;
    SelectableComboBoxModel model = new SelectableComboBoxModel();
    Selectable<DataNode> selected = null;

    GroupData group = getSelectedGroup();
    ExperimenterData user = getSelectedUser();
    long userID = -1;
    if (user != null)
        userID = user.getId();
    ExperimenterData loggedIn = ImporterAgent.getUserDetails();
    boolean isAdmin = ImporterAgent.isAdministrator();
    long loggedInID = loggedIn.getId();
    boolean userIsAdmin = isAdmin(userID);
    for (DataNode node : listItems) {
        exp = getExperimenter(node.getOwner());
        lines = new ArrayList<String>();
        if (exp != null) {
            lines.add("<b>Owner: </b>" + EditorUtil.formatExperimenter(exp));
        }
        lines.addAll(UIUtilities.wrapStyleWord(node.getFullName()));
        tooltips.add(UIUtilities.formatToolTipText(lines));

        boolean selectable = true;
        if (!node.isDefaultNode()) {
            selectable = canLink(node.getDataObject(), userID, group, loggedInID, isAdmin, userIsAdmin);
        }

        Selectable<DataNode> comboBoxItem = new Selectable<DataNode>(node, selectable);
        if (select != null && node.getDataObject().getId() == select.getDataObject().getId())
            selected = comboBoxItem;

        model.addElement(comboBoxItem);
    }

    ComboBoxToolTipRenderer renderer = createComboboxRenderer();
    renderer.setTooltips(tooltips);
    comboBox.setModel(model);
    comboBox.setRenderer(renderer);

    if (selected != null)
        comboBox.setSelectedItem(selected);

    if (itemListener != null)
        comboBox.addItemListener(itemListener);
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.LocationDialog.java

/**
 * Populates the JComboBox with the user details provided, 
 * selecting the logged in user and attaching the item listener.
 * //  w w  w  .j a  v a2  s .  c o  m
 * @param comboBox The JComboBox to populate
 * @param group The group being displayed
 * @param itemListener An item listener to add for the JComboBox
 * @param userID The id of the user.
 */
private void displayUsers(JComboBox comboBox, GroupData group, ItemListener itemListener, long userID) {

    if (comboBox == null || group == null)
        return;

    if (itemListener != null)
        comboBox.removeItemListener(itemListener);
    comboBox.removeAllItems();

    DefaultComboBoxModel model = new SelectableComboBoxModel();
    Selectable<ExperimenterDisplay> selected = null;

    List<ExperimenterData> members = sort(group.getExperimenters());
    boolean canImportAs;
    Selectable<ExperimenterDisplay> item;
    List<String> tooltips = new ArrayList<String>(members.size());
    List<String> lines;
    for (ExperimenterData user : members) {
        canImportAs = canImportForUserInGroup(user, group);
        item = new Selectable<ExperimenterDisplay>(new ExperimenterDisplay(user), canImportAs);
        if (user.getId() == userID)
            selected = item;
        lines = new ArrayList<String>();
        lines.addAll(UIUtilities.wrapStyleWord(EditorUtil.formatExperimenter(user)));
        tooltips.add(UIUtilities.formatToolTipText(lines));
        model.addElement(item);
    }
    ComboBoxToolTipRenderer renderer = createComboboxRenderer();
    renderer.setTooltips(tooltips);
    comboBox.setModel(model);
    comboBox.setRenderer(renderer);

    if (selected != null)
        comboBox.setSelectedItem(selected);

    if (itemListener != null)
        comboBox.addItemListener(itemListener);
}

From source file:org.smart.migrate.ui.MappingDialog.java

private void initTables(JComboBox comboBox, MetaDao metaDao, Connection connection) {
    comboBox.removeAllItems();
    List<String> tables = metaDao.getTables(connection);
    for (String table : tables) {
        comboBox.addItem(table);//from  w w w  .j a v a2 s. c o  m
    }
}

From source file:org.smart.migrate.ui.MigrateMain.java

private void initDBTypes(JComboBox comboBox) {
    comboBox.removeAllItems();
    for (DBType dBType : DBType.values()) {
        comboBox.addItem(dBType);//w  ww  .j  a v  a2 s  .  com
    }
}

From source file:org.smart.migrate.ui.RelationDialog.java

private void initTables(JComboBox comboBox) {
    comboBox.removeAllItems();
    List<String> tables = migratePlan.getSourceTableNames();
    for (String table : tables) {
        comboBox.addItem(table);//from   w  w  w  .ja v  a2  s. com
    }
}

From source file:org.smart.migrate.ui.RelationDialog.java

private void initFields(JComboBox comboBox, String table) {
    comboBox.removeAllItems();
    List<Field> fields = metaDao.getFieldsOfTable(connection, table);
    for (Field field : fields) {
        comboBox.addItem(field.getName());
    }/*from   ww w  .ja  v  a  2s.c om*/
}