Java Code Examples for javax.swing.DefaultComboBoxModel#addElement()

The following examples show how to use javax.swing.DefaultComboBoxModel#addElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the version combo-box. It sets its model (to match the versions
 * in library details) and selected item (to match the specified installed
 * version). 
 * 
 * @param installedVersion version to select in version combo-box.
 */
private void updateInstalledCombo(Library.Version installedVersion) {
    DefaultComboBoxModel<Library.Version> model = new DefaultComboBoxModel<>();
    Library.Version[] versions = libraryDetails.getVersions();
    if (versions == null) {
        if (installedVersion == null) {
            // PENDING insert dummy item that will show 'Loading versions'
        } else {
            model.addElement(installedVersion);
        }
    } else {
        for (Library.Version version : versions) {
            model.addElement(version);
        }
    }
    installVersionCombo.setModel(model);
    lastSelectedVersion = installedVersion;
    installVersionCombo.setSelectedItem(installedVersion);
}
 
Example 2
Source File: MyEditingGraphMousePlugin.java    From cloudml with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String selectClientPortInstance(RelationshipInstance bi) {
    JPanel panel = new JPanel();
    panel.add(new JLabel("Please make a selection:"));
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (ComponentInstance ai : dm.getComponentInstances()) {
        if (ai instanceof InternalComponentInstance) {
            for (RequiredPortInstance ci : ((InternalComponentInstance) ai).getRequiredPorts()) {
                System.out.println(bi.getType().getRequiredEnd() + " #### " + ci.getType());
                if (ci.getType().equals(bi.getType().getRequiredEnd())) {
                    model.addElement(ci);
                }
            }
        }
    }
    JComboBox comboBox = new JComboBox(model);
    panel.add(comboBox);

    int result = JOptionPane.showConfirmDialog(null, panel, "RequiredPort", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
    switch (result) {
        case JOptionPane.OK_OPTION:
            bi.setRequiredEnd((RequiredPortInstance) comboBox.getSelectedItem());
            return ((RequiredPortInstance) comboBox.getSelectedItem()).getOwner().getName();
    }
    return "";
}
 
Example 3
Source File: SelectorsGroupEditor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Creates new form CssRuleCreateActionDialog */
public SelectorsGroupEditor() {
    initComponents();
    String[] htmlTags = getHtmlTagNames();

    // Optional prefix
    DefaultComboBoxModel htmlTagsModel1 = new DefaultComboBoxModel();
    htmlTagsModel1.addElement(NONE);
    htmlTagsModel1.addElement("a:link");
    htmlTagsModel1.addElement("a:visited");
    htmlTagsModel1.addElement("a:hover");
    htmlTagsModel1.addElement("a:active");
    for( int i=0; i< htmlTags.length; i++){
        htmlTagsModel1.addElement(htmlTags[i]);
    }

    DefaultComboBoxModel htmlTagsModel = new DefaultComboBoxModel();
    //htmlTagsModel.addElement(NONE);
    for( int i=0; i< htmlTags.length; i++){
        htmlTagsModel.addElement(htmlTags[i]);
    }
    selectElementComboBox.setModel(htmlTagsModel);
    classPrefixComboBox.setModel(htmlTagsModel1);
    ruleHierarchyList.setModel(selectedRules);
    removeRuleButton.setEnabled(false);
}
 
Example 4
Source File: ETable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private ComboBoxModel<String> getSearchComboModel() {
    DefaultComboBoxModel<String> result = new DefaultComboBoxModel();
    for (Enumeration<TableColumn> en = getColumnModel().getColumns(); en.hasMoreElements(); ) {
        TableColumn column = en.nextElement();
        if (column instanceof ETableColumn) {
            ETableColumn etc = (ETableColumn)column;
            Object value = etc.getHeaderValue();
            String valueString = "";
            if (value != null) {
                valueString = value.toString();
            }
            valueString = getColumnDisplayName(valueString);
            result.addElement(valueString);
        }
    }
    return result;
}
 
Example 5
Source File: CrewEditor.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
public DefaultComboBoxModel<String> setUpSponsorCBModel(String country) {

		//List<String> sponsors = UnitManager.getSponsorByCountryID(id);
		List<String> sponsors = new ArrayList<>();

		sponsors.add(ReportingAuthorityType.MARS_SOCIETY_L.getName());
//		// Retrieve the sponsor from the selected country 		
		if (!country.isBlank())
			sponsors.add(UnitManager.mapCountry2Sponsor(country));		
				
		DefaultComboBoxModel<String> m = new DefaultComboBoxModel<String>();
		Iterator<String> j = sponsors.iterator();

		while (j.hasNext()) {
			String s = j.next();
			m.addElement(s);
		}
		return m;
	}
 
Example 6
Source File: ModOptionUI.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new {@code ModOptionUI} for the given
 * {@code ModOption}.
 *
 * @param option The {@code ModOption} to make a user interface for
 * @param editable boolean whether user can modify the setting
 */
public ModOptionUI(final ModOption option, boolean editable) {
    super(option, editable);

    DefaultComboBoxModel<FreeColModFile> model
        = new DefaultComboBoxModel<>();
    for (FreeColModFile choice : option.getChoices()) {
        model.addElement(choice);
    }
    this.box = new JComboBox<>();
    this.box.setModel(model);
    this.box.setRenderer(new BoxRenderer());
    if (option.getValue() != null) {
        this.box.setSelectedItem(option.getValue());
    }
    initialize();
}
 
Example 7
Source File: DemoUtils.java    From java-ocr-api with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void loadPrefs(Preferences prefs, String prefKey, JComboBox combo) {

        DefaultComboBoxModel comboModel = new DefaultComboBoxModel();
        String recents = prefs.get(prefKey, null);
        if (recents != null) {
            StringTokenizer st = new StringTokenizer(recents, DELIMITER);
            while (st.hasMoreTokens()) {
                comboModel.addElement(st.nextToken());
            }
        }

        combo.setModel(comboModel);
    }
 
Example 8
Source File: DSWorkbenchProfileDialog.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
private void fireServerChangedEvent(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_fireServerChangedEvent
    String server = (String) jAccountServerBox.getSelectedItem();
    if(!Arrays.asList(ServerManager.getLocalServers()).contains(server)) {
        jAccountTribeBox.setModel(new DefaultComboBoxModel(new String[] {"Bitte Laden dr\u00fccken"}));
        return;
    }
    Collection<Tribe> tribes = DataHolder.getSingleton().getTribesForServer(server).values();
    Tribe[] aTribes = tribes.toArray(new Tribe[]{});
    Arrays.sort(aTribes, Tribe.CASE_INSENSITIVE_ORDER);
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (Tribe tribe : aTribes) {
        model.addElement(tribe);
    }
    jAccountTribeBox.setModel(model);
}
 
Example 9
Source File: LocksViewSupport.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void handleAggregationChanged(boolean updateSecondary) {
    if (updateSecondary) {
        int sel = secondCombo.getSelectedIndex();
        
        DefaultComboBoxModel model = (DefaultComboBoxModel)secondCombo.getModel();
        while (model.getSize() > 1) model.removeElementAt(1);
        
        if (!Aggregation.CLASS.equals(firstCombo.getSelectedItem()) &&
            !Aggregation.OBJECT.equals(firstCombo.getSelectedItem()))
                model.addElement(Aggregation.CLASS);
        
        if (!Aggregation.CLASS.equals(firstCombo.getSelectedItem()) &&
            !Aggregation.OBJECT.equals(firstCombo.getSelectedItem()))
                model.addElement(Aggregation.OBJECT);
        
        if (!Aggregation.THREAD_BLOCKED.equals(firstCombo.getSelectedItem()))
            model.addElement(Aggregation.THREAD_BLOCKED);
        
        if (!Aggregation.THREAD_BLOCKING.equals(firstCombo.getSelectedItem()))
            model.addElement(Aggregation.THREAD_BLOCKING);
        
        secondCombo.setSelectedIndex(sel < secondCombo.getItemCount() ? sel : 0);
    }
    
    updateButton.setEnabled(lastMode != modeCombo.getSelectedIndex() ||
                            lastPrimary != firstCombo.getSelectedItem() ||
                            lastSecondary != secondCombo.getSelectedItem());
    
}
 
Example 10
Source File: ResolveBrokenRuntimePlatform.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void updatePlatforms() {
    final SourceLevelQuery.Result slqr = SourceLevelQuery.getSourceLevel2(prj.getProjectDirectory());
    final String sl = slqr.getSourceLevel();
    final SourceLevelQuery.Profile profile = slqr.getProfile();
    final DefaultComboBoxModel<Object> model = (DefaultComboBoxModel<Object>) platforms.getModel();
    model.removeAllElements();
    for (J2SERuntimePlatformProvider pp : prj.getLookup().lookupAll(J2SERuntimePlatformProvider.class)) {
        for (JavaPlatform jp : pp.getPlatformType(new SpecificationVersion(sl), profile)) {
            model.addElement(jp);
        }
    }
}
 
Example 11
Source File: NamedNativeQueryPanel.java    From jeddict with Apache License 2.0 5 votes vote down vote up
private void initResultSetMappingModel() {
    resultSetMapping_jComboBox.removeAllItems();
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    model.addElement(null);
    entity.getSqlResultSetMapping().forEach(mapping -> model.addElement(mapping.getName()));
    resultSetMapping_jComboBox.setModel(model);
}
 
Example 12
Source File: SelectProjectPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void loadComboBox() {
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    Project[] prjs = OpenProjects.getDefault().getOpenProjects();
    Arrays.sort(prjs, Util.projectDisplayNameComparator());
    for (int i = 0; i < prjs.length; i++) {
        if (prjs[i] != data.getProject()) {
            // ignore the currently active project..
            model.addElement(prjs[i]);
        }
    }
    if (model.getSize() == 0) {
        model.addElement(EMPTY);
    }
    comProject.setModel(model);
}
 
Example 13
Source File: TreePosTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add another entry to the list of errors.
 * @param file The file containing the error
 * @param check The condition that was being tested, and which failed
 * @param encl the enclosing tree node
 * @param self the tree node containing the error
 */
void addEntry(JavaFileObject file, String check, Info encl, Info self) {
    Entry e = new Entry(file, check, encl, self);
    DefaultComboBoxModel m = (DefaultComboBoxModel) entries.getModel();
    m.addElement(e);
    if (m.getSize() == 1)
        entries.setSelectedItem(e);
}
 
Example 14
Source File: AddFIActionPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates new form AddFIActionPanel */
public AddFIActionPanel(StrutsConfigDataObject dObject) {
    config = dObject;
    initComponents();
    List actions = StrutsConfigUtilities.getAllActionsInModule(config);
    DefaultComboBoxModel model = (DefaultComboBoxModel)cbAction.getModel();
    //model.removeAllElements();
    Iterator iter = actions.iterator();
    while (iter.hasNext())
        model.addElement(((Action)iter.next()).getAttributeValue("path"));
}
 
Example 15
Source File: CheckAttributedTree.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add another entry to the list of errors.
 * @param file The file containing the error
 * @param check The condition that was being tested, and which failed
 * @param encl the enclosing tree node
 * @param self the tree node containing the error
 */
void addEntry(JavaFileObject file, String check, Info encl, Info self) {
    Entry e = new Entry(file, check, encl, self);
    DefaultComboBoxModel m = (DefaultComboBoxModel) entries.getModel();
    m.addElement(e);
    if (m.getSize() == 1)
        entries.setSelectedItem(e);
}
 
Example 16
Source File: AbstractUnitOptionUI.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void itemStateChanged(ItemEvent e) {
    // When the unit type changes, we have to reset the role choices
    JComboBox<String> box = this.roleUI.getComponent();
    DefaultComboBoxModel<String> model;
    boolean enable = false;
    UnitType type = (UnitType)this.typeUI.getComponent().getSelectedItem();
    if (type != null && type.hasAbility(Ability.CAN_BE_EQUIPPED)) {
        final Specification spec = type.getSpecification();
        final NationType nt = getOption().getNationType();
        int n = 0;
        model = new DefaultComboBoxModel<>();
        for (String ri : getOption().getRole().getChoices()) {
            Role role = spec.getRole(ri);
            if (role.isAvailableTo(type, nt)) {
                model.addElement(ri);
                n++;
            }
        }
        enable = n > 1 && isEditable();
    } else {
        model = new DefaultComboBoxModel<>(new String[] {
                Specification.DEFAULT_ROLE_ID });
    }
    box.setModel(model);
    box.setEnabled(enable);
}
 
Example 17
Source File: CrewEditor.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public DefaultComboBoxModel<String> setUpGenderCBModel() {

		List<String> genderList = new ArrayList<String>(2);
		genderList.add("M");
		genderList.add("F");
		DefaultComboBoxModel<String> m = new DefaultComboBoxModel<String>();

		Iterator<String> i = genderList.iterator();
		while (i.hasNext()) {
			String s = i.next();
			m.addElement(s);
		}

		return m;
	}
 
Example 18
Source File: SpellcheckerOptionsPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ComboBoxModel getLocaleModel() {
    DefaultComboBoxModel dlm = new DefaultComboBoxModel();
    List<Locale> locales = new ArrayList<Locale>(Arrays.asList(Locale.getAvailableLocales()));
    
    Collections.sort(locales, new LocaleComparator());
    
    for (Locale l : locales) {
        dlm.addElement(l);
    }
    
    return dlm;
}
 
Example 19
Source File: EditSettlementDialog.java    From freecol with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create an EditSettlementDialog.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 * @param is The {@code IndianSettlement} to edit.
 */
public EditSettlementDialog(FreeColClient freeColClient, JFrame frame,
                            final IndianSettlement is) {
    super(freeColClient, frame);

    this.is = is;

    this.name = new JTextField(is.getName(), 30);

    DefaultComboBoxModel<Nation> nationModel
        = new DefaultComboBoxModel<>();
    for (Nation n : getSpecification().getIndianNations()) {
        nationModel.addElement(n);
    }
    this.owner = new JComboBox<>(nationModel);
    this.owner.setSelectedItem(is.getOwner().getNation());
    this.owner.addItemListener(this);
    this.owner.setRenderer(new FreeColComboBoxRenderer<Nation>());

    this.capital = new JCheckBox();
    this.capital.setSelected(is.isCapital());

    this.skill = new JComboBox<>(getSkillModel());
    this.skill.setSelectedItem(is.getLearnableSkill());
    this.skill.setRenderer(new FreeColComboBoxRenderer<UnitType>());

    int unitCount = is.getUnitCount();
    SpinnerNumberModel spinnerModel
        = new SpinnerNumberModel(unitCount, 1, 20, 1);
    this.units = new JSpinner(spinnerModel);
    spinnerModel.setValue(unitCount);

    JPanel panel = new MigPanel(new MigLayout("wrap 2, gapx 20"));
    panel.add(Utility.localizedLabel("name"));
    panel.add(this.name);
    panel.add(Utility.localizedLabel("nation"));
    panel.add(this.owner);
    panel.add(Utility.localizedLabel("capital"));
    panel.add(this.capital);
    panel.add(Utility.localizedLabel("skillTaught"));
    panel.add(this.skill);
    panel.add(Utility.localizedLabel("units"));
    panel.add(this.units);

    List<ChoiceItem<IndianSettlement>> c = choices();
    c.add(new ChoiceItem<>(Messages.message("ok"), is).okOption());
    c.add(new ChoiceItem<>(Messages.message("editSettlementDialog.removeSettlement"), null));
    c.add(new ChoiceItem<>(Messages.message("cancel"),
                           (IndianSettlement)null).cancelOption().defaultOption());
    initializeDialog(frame, DialogType.QUESTION, true, panel, new ImageIcon(
        getImageLibrary().getSmallSettlementImage(is)), c);
}
 
Example 20
Source File: JShellOptions2.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Creates new form JShellOptions
 */
public JShellOptions2(Project project) {
    this.project = project;
    initComponents();
    
    DefaultComboBoxModel mdl = new DefaultComboBoxModel();
    mdl.addElement(LoaderPolicy.SYSTEM);
    mdl.addElement(LoaderPolicy.CLASS);
    mdl.addElement(LoaderPolicy.EVAL);
    
    loaderSelect.setModel(mdl);
    loaderSelect.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            RunOptionsModel.LoaderPolicy pol = (RunOptionsModel.LoaderPolicy)value;
            if (pol == null) {
                pol = RunOptionsModel.LoaderPolicy.SYSTEM;
            }
            setText(NbBundle.getMessage(JShellOptions2.class, "JShellOptions.loader." + pol.name().toLowerCase()));
            return this;
        }
    });
    
    source.addActionListener(this::classNameChanged);
    source.addFocusListener(new FocusAdapter() {
       @Override
        public void focusLost(FocusEvent e) {
            if (e.getComponent() == source) {
                classNameChanged(null);
            }
        }
    });
    loaderSelect.addItemListener(this);
    cbMember.setRenderer(new MemberRenderer());
    
    source.getActionMap().put("type-browse", new BrowseAction());
    source.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, KeyEvent.CTRL_DOWN_MASK), "type-browse");

    enableDisable();
}