Example usage for javax.swing ComboBoxModel setSelectedItem

List of usage examples for javax.swing ComboBoxModel setSelectedItem

Introduction

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

Prototype

void setSelectedItem(Object anItem);

Source Link

Document

Set the selected item.

Usage

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 {/* w w  w . j  a v  a 2s. 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:com.jwmsolutions.timeCheck.gui.TodoForm.java

private JComboBox getJcbListsObject() {
    if (jcbLists == null) {
        ComboBoxModel jcbListModel = new DefaultComboBoxModel(new String[] { "Item One", "Item Two" });
        jcbListModel.setSelectedItem("");
        jcbLists = new JComboBox();
        jcbLists.setModel(jcbListModel);
        jcbLists.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
        jcbLists.setAutoscrolls(true);//from  w ww.  ja va2 s.co  m
        jcbLists.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent evt) {
                jcbListsItemStateChanged(evt);
            }
        });
    }
    return jcbLists;
}

From source file:com.jwmsolutions.timeCheck.gui.TodoForm.java

private JComboBox getJcbProjects() {
    if (jcbProjects == null) {
        ComboBoxModel jcbProjectsModel = new DefaultComboBoxModel(new String[] { "Item One", "Item Two" });
        jcbProjectsModel.setSelectedItem("");
        jcbProjects = new JComboBox();
        jcbProjects.setModel(jcbProjectsModel);
        jcbProjects.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
        jcbProjects.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent evt) {
                jcbProjectsItemStateChanged(evt);
            }/*from  w w w .ja v  a 2 s.co m*/
        });
    }
    return jcbProjects;
}

From source file:io.github.jeddict.jpa.modeler.source.generator.ui.GenerateCodeDialog.java

private void populatePackageCombo(JComboBox packageCombo, ProjectInfo projectInfo) {
    if (projectInfo.getSourceGroup() != null) {
        packageCombo.setRenderer(PackageView.listRenderer());
        ComboBoxModel model = PackageView.createListView(projectInfo.getSourceGroup());
        if (model.getSize() > 0) {
            model.setSelectedItem(model.getElementAt(0));
        }//from  w w  w.  j  a  v a 2s . co m
        packageCombo.setModel(model);
    }
}

From source file:io.github.jeddict.jpa.modeler.source.generator.ui.GenerateCodeDialog.java

private void setPackage(JComboBox packageCombo, String _package) {
    ComboBoxModel model = packageCombo.getModel();
    for (int i = 0; i < model.getSize(); i++) {
        if (model.getElementAt(i).toString().equals(_package)) {
            model.setSelectedItem(model.getElementAt(i));
            return;
        }//  w  w w .  ja  va 2s.com
    }
    ((JTextComponent) packageCombo.getEditor().getEditorComponent()).setText(_package);
}

From source file:com.peterbochs.instrument.InstrumentPanel.java

private JComboBox getJToComboBox() {
    if (jToComboBox == null) {
        ComboBoxModel jToComboBoxModel = new DefaultComboBoxModel(
                new String[] { "1GB", "100MB", "10MB", "1MB" });
        jToComboBox = new JComboBox();
        jToComboBox.setModel(jToComboBoxModel);
        jToComboBox.setEditable(true);//  w  w  w. ja va  2 s . c o  m
        jToComboBoxModel.setSelectedItem("100MB");
        jToComboBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jToComboBoxActionPerformed(evt);
            }
        });
    }
    return jToComboBox;
}

From source file:org.apache.jmeter.visualizers.ViewResultsFullVisualizer.java

/**
 * Create the drop-down list to changer render
 * @return List of all render (implement ResultsRender)
 *//*w w w .j ava2s .c om*/
private Component createComboRender() {
    ComboBoxModel<ResultRenderer> nodesModel = new DefaultComboBoxModel<>();
    // drop-down list for renderer
    selectRenderPanel = new JComboBox<>(nodesModel);
    selectRenderPanel.setActionCommand(COMBO_CHANGE_COMMAND);
    selectRenderPanel.addActionListener(this);

    // if no results render in jmeter.properties, load Standard (default)
    List<String> classesToAdd = Collections.<String>emptyList();
    try {
        classesToAdd = JMeterUtils.findClassesThatExtend(ResultRenderer.class);
    } catch (IOException e1) {
        // ignored
    }
    String textRenderer = JMeterUtils.getResString("view_results_render_text"); // $NON-NLS-1$
    Object textObject = null;
    Map<String, ResultRenderer> map = new HashMap<>(classesToAdd.size());
    for (String clazz : classesToAdd) {
        try {
            // Instantiate render classes
            final ResultRenderer renderer = (ResultRenderer) Class.forName(clazz).newInstance();
            if (textRenderer.equals(renderer.toString())) {
                textObject = renderer;
            }
            renderer.setBackgroundColor(getBackground());
            map.put(renderer.getClass().getName(), renderer);
        } catch (Exception e) {
            log.warn("Error loading result renderer:" + clazz, e);
        }
    }
    if (VIEWERS_ORDER.length() > 0) {
        String[] keys = VIEWERS_ORDER.split(",");
        for (String key : keys) {
            if (key.startsWith(".")) {
                key = "org.apache.jmeter.visualizers" + key; //$NON-NLS-1$
            }
            ResultRenderer renderer = map.remove(key);
            if (renderer != null) {
                selectRenderPanel.addItem(renderer);
            } else {
                log.warn("Missing (check spelling error in renderer name) or already added(check doublon) "
                        + "result renderer, check property 'view.results.tree.renderers_order', renderer name:'"
                        + key + "'");
            }
        }
    }
    // Add remaining (plugins or missed in property)
    for (ResultRenderer renderer : map.values()) {
        selectRenderPanel.addItem(renderer);
    }
    nodesModel.setSelectedItem(textObject); // preset to "Text" option
    return selectRenderPanel;
}

From source file:org.netbeans.jcode.ejb.facade.SessionBeanPanel.java

@Override
public void init(String _package, Project project, SourceGroup sourceGroup) {
    pref = ProjectUtils.getPreferences(project, SessionBeanData.class, true);
    if (sourceGroup != null) {
        packageCombo.setRenderer(PackageView.listRenderer());
        ComboBoxModel model = PackageView.createListView(sourceGroup);
        if (model.getSize() > 0) {
            model.setSelectedItem(model.getElementAt(0));
        }/*from ww w . j  av  a2 s .com*/
        packageCombo.setModel(model);
        addChangeListener(packageCombo);
        if (StringUtils.isBlank(_package)) {
            setPackage(DEFAULT_PACKAGE);
        } else {
            setPackage(_package + '.' + DEFAULT_PACKAGE);
        }
    }
    addChangeListener(prefixField);
    addChangeListener(suffixField);
}

From source file:org.netbeans.jcode.ejb.facade.SessionBeanPanel.java

private void setPackage(String _package) {
    ComboBoxModel model = packageCombo.getModel();
    for (int i = 0; i < model.getSize(); i++) {
        if (model.getElementAt(i).toString().equals(_package)) {
            model.setSelectedItem(model.getElementAt(i));
            return;
        }//from   w  w  w . ja v  a2  s.  c o  m
    }
    ((JTextComponent) packageCombo.getEditor().getEditorComponent()).setText(_package);
}

From source file:org.netbeans.jcode.mvc.controller.MVCPanel.java

@Override
public void init(String _package, Project project, SourceGroup sourceGroup) {
    pref = ProjectUtils.getPreferences(project, MVCData.class, true);
    this.project = project;
    this.sourceGroup = sourceGroup;

    if (sourceGroup != null) {
        packageCombo.setRenderer(PackageView.listRenderer());
        ComboBoxModel model = PackageView.createListView(sourceGroup);
        if (model.getSize() > 0) {
            model.setSelectedItem(model.getElementAt(0));
        }// w ww  .  j a v a  2  s. c om
        packageCombo.setModel(model);
        addChangeListener(packageCombo);
        if (StringUtils.isBlank(_package)) {
            _package = DEFAULT_PACKAGE;
        } else {
            _package = _package + '.' + DEFAULT_PACKAGE;
        }
        setPackage(_package);
    }
    addChangeListener(prefixField);
    addChangeListener(suffixField);

    eventObserversPanel.removeAll();

    for (ControllerEventType type : ControllerEventType.values()) {
        JCheckBox eventTypeBox = new JCheckBox();
        org.openide.awt.Mnemonics.setLocalizedText(eventTypeBox, type.toString()); // NOI18N
        eventObserversPanel.add(eventTypeBox);
        eventTypeBoxs.put(eventTypeBox, type);
    }

    final RestSupport restSupport = project.getLookup().lookup(RestSupport.class);
    //        if (restSupport != null) {
    //            if (restSupport.isEE5() && restSupport.hasJersey1(true)
    //                    || restSupport.hasSpringSupport() && !restSupport.hasJersey2(true)) {
    //                useJersey = true;
    //            }
    //        }
    if (restSupport != null) {
        ScanDialog.runWhenScanFinished(() -> {
            boolean configured;//restSupport.isRestSupportOn();
            configured = restSupport.hasJerseyServlet();
            restApplications = restSupport.getRestApplications();
            if (!configured) {
                configured = restApplications != null && !restApplications.isEmpty();
            }
            if (configDialog != null) {
                configDialog.setRestApplicationClasses(restApplications);
            }
            configurREST(configured);
        }, getMessage(MVCPanel.class, "MVCPanel.scanningExistingApp.text"));

    }
}