Example usage for javax.swing ComboBoxModel getSize

List of usage examples for javax.swing ComboBoxModel getSize

Introduction

In this page you can find the example usage for javax.swing ComboBoxModel getSize.

Prototype

int getSize();

Source Link

Document

Returns the length of the list.

Usage

From source file:Main.java

/**
 * @param comboBox/*ww w . j  a  va 2  s . c  om*/
 * @param value
 * @return if the comboBox contains the specified value
 */
public static boolean containsValue(JComboBox comboBox, String value) {
    ComboBoxModel model = comboBox.getModel();
    int size = model.getSize();
    for (int i = 0; i < size; i++) {
        Object element = model.getElementAt(i);
        if (element.equals(value)) {
            return true;
        }
    }
    return false;
}

From source file:org.jdal.swing.form.FormUtils.java

/**
 * Return a List of Objects from a ComboBoxModel
 * @param model ComboBoxModel//from   w w w .  j ava2 s  .  c  om
 * @return a list of Objects with ComboBoxModel items
 */
public static List<Object> getComboModelList(ComboBoxModel<?> model) {
    ArrayList<Object> list = new ArrayList<Object>();
    for (int i = 0; i < model.getSize(); i++) {
        list.add(model.getElementAt(i));
    }
    return list;
}

From source file:Main.java

public int selectionForKey(char aKey, ComboBoxModel model) {
    int selIx = 01;
    Object sel = model.getSelectedItem();
    if (sel != null) {
        for (int i = 0; i < model.getSize(); i++) {
            if (sel.equals(model.getElementAt(i))) {
                selIx = i;/*  w  w  w . jav  a  2s  .  co  m*/
                break;
            }
        }
    }
    long curTime = System.currentTimeMillis();
    if (curTime - lastKeyTime < 300) {
        pattern += ("" + aKey).toLowerCase();
    } else {
        pattern = ("" + aKey).toLowerCase();
    }
    lastKeyTime = curTime;
    for (int i = selIx + 1; i < model.getSize(); i++) {
        String s = model.getElementAt(i).toString().toLowerCase();
        if (s.startsWith(pattern)) {
            return i;
        }
    }
    for (int i = 0; i < selIx; i++) {
        if (model.getElementAt(i) != null) {
            String s = model.getElementAt(i).toString().toLowerCase();
            if (s.startsWith(pattern)) {
                return i;
            }
        }
    }
    return -1;
}

From source file:ja.lingo.application.gui.main.settings.appearance.AppearanceGui.java

private void setSelectedFontSize(int fontSize) {
    ComboBoxModel model = fontSizeComboBox.getModel();
    for (int i = 0; i < model.getSize(); i++) {
        Integer value = (Integer) model.getElementAt(i);
        if (value.equals(fontSize)) {
            fontSizeComboBox.setSelectedItem(value);
            return;
        }//  w w w.j  a v a  2s . c  o  m
    }
    // TODO refactoring needed: move out default size + allowed sizes
    LOG.warn("Incorrect font size: " + fontSize + ", setting size to default");
    setSelectedFontSize(DEFAULT_FONT_SIZE); // NOTE potential recursion appearance on re-factoring
}

From source file:ja.lingo.application.gui.main.settings.appearance.AppearanceGui.java

private void setSelectedFontFace(String fontFace) {
    ComboBoxModel model = fontFaceComboBox.getModel();
    for (int i = 0; i < model.getSize(); i++) {
        String value = (String) model.getElementAt(i);
        System.out.println(value);
        System.out.println(fontFace);
        if (value.equals(fontFace)) {
            fontFaceComboBox.setSelectedItem(value);
            return;
        }//from   w ww.  j  a  v  a 2 s .c om
    }
    // TODO refactoring needed: move out default size + allowed sizes
    LOG.warn("Incorrect font face: " + fontFace + ", setting font to default");
    setSelectedFontFace("SansSerif"); // NOTE potential recursion appearance on re-factoring
}

From source file:com.tascape.qa.th.android.tools.UiAutomatorViewer.java

private void detectDevices() {
    List<String> devices = Adb.getSerialProduct().entrySet().stream()
            .map(entry -> entry.getKey() + ":" + entry.getValue()).collect(Collectors.toList());
    ComboBoxModel<String> model = new DefaultComboBoxModel<>(devices.toArray(new String[0]));
    jcbDevices.setModel(model);/*from w  w w .java 2s .  c o m*/
    if (model.getSize() == 0) {
        JOptionPane.showMessageDialog(jcbDevices.getTopLevelAncestor(), "No attached Android device found.");
        this.jbLaunch.setEnabled(false);
    } else {
        this.jbLaunch.setEnabled(true);
    }
}

From source file:au.org.ala.delta.intkey.ui.WebSearchDialog.java

private void loadSearchEngines(File file, JComboBox cmb) {

    List<SearchEngineDescriptor> engines = new ArrayList<WebSearchDialog.SearchEngineDescriptor>();
    try {/*from  www . ja va2  s.c o  m*/
        List<String> lines = FileUtils.readLines(file);
        for (String line : lines) {
            SearchEngineDescriptor desc = parseSearchEngineDescriptor(line);
            if (desc != null) {
                engines.add(desc);
            } else {
                Logger.log("Could not parse search engine descriptor: " + line);
            }
        }

        ComboBoxModel model = new DefaultComboBoxModel(engines.toArray());
        cmb.setModel(model);
        if (model.getSize() > 0) {
            model.setSelectedItem(model.getElementAt(0));
        }

    } catch (IOException ioex) {
        throw new RuntimeException(ioex);
    }
}

From source file:de.fhg.iais.asc.ui.parts.HarvesterPanel.java

private boolean setSelectedString(JComboBox comboBox, String stringToSelect) {
    final ComboBoxModel model = comboBox.getModel();

    int size = model.getSize();
    for (int index = 0; index < size; index++) {
        if (model.getElementAt(index).toString().equals(stringToSelect)) {
            comboBox.setSelectedIndex(index);
            return true;
        }//from ww  w .j  a v a2 s  .com
    }

    return false;
}

From source file:de.fhg.iais.asc.ui.parts.TransformersPanel.java

/**
 * helper//from   ww  w .  j a v a  2s . co m
 */
private boolean setSelectedString(JComboBox comboBox, String stringToSelect) {
    final ComboBoxModel model = comboBox.getModel();

    int size = model.getSize();
    for (int index = 0; index < size; index++) {
        if (model.getElementAt(index).toString().equals(stringToSelect)) {
            comboBox.setSelectedIndex(index);
            return true;
        }
    }

    return false;
}

From source file:com.anrisoftware.prefdialog.fields.historycombobox.HistoryComboBoxField.java

private MutableComboBoxModel<?> createMutableModel(ComboBoxModel<?> model) {
    if (model instanceof MutableComboBoxModel) {
        return (MutableComboBoxModel<?>) model;
    }/* www. j  ava2  s . c  o m*/
    DefaultComboBoxModel<Object> mutableModel = new DefaultComboBoxModel<Object>();
    for (int i = 0; i < model.getSize(); i++) {
        mutableModel.addElement(model.getElementAt(i));
    }
    return mutableModel;
}