Java Code Examples for javax.swing.MutableComboBoxModel

The following examples show how to use javax.swing.MutableComboBoxModel. These examples are extracted from open source projects. 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 Project: netbeans   Source File: PlatformComponentFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns <code>JComboBox</code> containing all suites. Also see
 * {@link #addUserSuite}.
 */
public static JComboBox getSuitesComboBox() {
    MutableComboBoxModel model = new SuiteListModel(userSuites);
    Project[] projects = OpenProjects.getDefault().getOpenProjects();
    for (int i = 0; i < projects.length; i++) {
        String suiteDir = SuiteUtils.getSuiteDirectoryPath(projects[i]);
        if (suiteDir != null) {
            model.addElement(suiteDir);
        }
    }
    JComboBox suiteCombo = new JComboBox(model);
    if (model.getSize() > 0) {
        suiteCombo.setSelectedIndex(0);
    }
    return suiteCombo;
}
 
Example 2
Source Project: visualvm   Source File: ActionUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Insert the given item into the combo box, and set it as first selected
 * item.  If the item already exists, it is removed, so there are no
 * duplicates.
 * @param combo
 * @param item
 */
public static void insertIntoCombo(JComboBox combo, Object item) {
    MutableComboBoxModel model = (MutableComboBoxModel) combo.getModel();
    if (model.getSize() == 0) {
        model.insertElementAt(item, 0);
        return;
    }

    Object o = model.getElementAt(0);
    if (o.equals(item)) {
        return;
    }
    model.removeElement(item);
    model.insertElementAt(item, 0);
    combo.setSelectedIndex(0);
}
 
Example 3
Source Project: jpexs-decompiler   Source File: ActionUtils.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Insert the given item into the combo box, and set it as first selected
 * item.  If the item already exists, it is removed, so there are no
 * duplicates.
 * @param combo
 * @param item the item to insert. if it's null, then nothing is inserted
 */
public static void insertIntoCombo(JComboBox combo, Object item) {
	if(item == null) {
		return;
	}
	MutableComboBoxModel model = (MutableComboBoxModel) combo.getModel();
	if (model.getSize() == 0) {
		model.insertElementAt(item, 0);
		return;
	}

	Object o = model.getElementAt(0);
	if (o.equals(item)) {
		return;
	}
	model.removeElement(item);
	model.insertElementAt(item, 0);
	combo.setSelectedIndex(0);
}
 
Example 4
private void updateComboBoxes(List<FormItem> items) {
    for (FormItem item : items) {
        JComponent field = item.getField();
        if (field instanceof JComboBox) {
            @SuppressWarnings("unchecked")
            JComboBox<String> box = (JComboBox<String>) field;
            List<String> newPossibleValues = item.getPossibleValues();
            if (!boxModelIsSame(box, newPossibleValues)) {
                MutableComboBoxModel<String> mmodel = (MutableComboBoxModel<String>) box.getModel();
                replaceBoxModelValues(mmodel, newPossibleValues);
                mmodel.setSelectedItem(item.getCurrentValue());
            }
        }
    }
}
 
Example 5
private void replaceBoxModelValues(MutableComboBoxModel<String> mmodel, List<String> newPossibleValues) {
    try {
        while (mmodel.getSize() > 0) {
            mmodel.removeElementAt(0);
        }
    } catch (Exception e) {
        // ignore weird index out of bounds exceptions
    }
    for (String value : newPossibleValues) {
        mmodel.addElement(value);
    }
}
 
Example 6
Source Project: bigtable-sql   Source File: SQLHistoryComboBoxModel.java    License: Apache License 2.0 5 votes vote down vote up
protected synchronized MutableComboBoxModel duplicateSharedDataModel()
{
	MutableComboBoxModel newModel = new DefaultComboBoxModel();
	for (int i = 0, limit = s_sharedDataModel.getSize(); i < limit; ++i)
	{
		SQLHistoryItem obj = (SQLHistoryItem)s_sharedDataModel.getElementAt(i);
		newModel.addElement(obj.clone());
	} 
	return newModel;
}
 
Example 7
Source Project: FlatLaf   Source File: LookAndFeelsComboBox.java    License: Apache License 2.0 4 votes vote down vote up
private MutableComboBoxModel<LookAndFeelInfo> getMutableModel() {
	return (MutableComboBoxModel<LookAndFeelInfo>) getModel();
}
 
Example 8
Source Project: netbeans   Source File: LocalServerController.java    License: Apache License 2.0 4 votes vote down vote up
public MutableComboBoxModel<LocalServer> getLocalServerModel() {
    return localServerComboBoxModel;
}
 
Example 9
Source Project: netbeans   Source File: LocalServerController.java    License: Apache License 2.0 4 votes vote down vote up
public void setLocalServerModel(MutableComboBoxModel<LocalServer> localServers) {
    localServerComboBoxModel = localServers;
    localServerComboBox.setModel(localServerComboBoxModel);
}
 
Example 10
Source Project: netbeans   Source File: CopyFilesVisual.java    License: Apache License 2.0 4 votes vote down vote up
public MutableComboBoxModel<LocalServer> getLocalServerModel() {
    return localServerController.getLocalServerModel();
}
 
Example 11
Source Project: netbeans   Source File: CopyFilesVisual.java    License: Apache License 2.0 4 votes vote down vote up
public void setLocalServerModel(MutableComboBoxModel<LocalServer> localServers) {
    localServerController.setLocalServerModel(localServers);
}
 
Example 12
Source Project: netbeans   Source File: ConfigureProjectPanel.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private MutableComboBoxModel<LocalServer> getLocalServers() {
    return (MutableComboBoxModel<LocalServer>) descriptor.getProperty(LOCAL_SERVERS);
}
 
Example 13
Source Project: netbeans   Source File: RunConfigurationPanel.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private MutableComboBoxModel<LocalServer> getLocalServerModel() {
    return (MutableComboBoxModel<LocalServer>) descriptor.getProperty(COPY_SRC_TARGETS);
}
 
Example 14
Source Project: netbeans   Source File: RunAsLocalWeb.java    License: Apache License 2.0 4 votes vote down vote up
public MutableComboBoxModel<LocalServer> getLocalServerModel() {
    return copyFilesVisual.getLocalServerModel();
}
 
Example 15
Source Project: netbeans   Source File: RunAsLocalWeb.java    License: Apache License 2.0 4 votes vote down vote up
public void setLocalServerModel(MutableComboBoxModel<LocalServer> localServers) {
    copyFilesVisual.setLocalServerModel(localServers);
}
 
Example 16
@Override
public MutableComboBoxModel<LocalServer> getLocalServerModel() {
    return null;
}
 
Example 17
@Override
public void setLocalServerModel(MutableComboBoxModel<LocalServer> localServers) {
}
 
Example 18
Source Project: netbeans   Source File: ConfigureNewProjectPanelVisual.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public MutableComboBoxModel<LocalServer> getLocalServerModel() {
    return localServerComponent.getLocalServerModel();
}
 
Example 19
Source Project: netbeans   Source File: ConfigureNewProjectPanelVisual.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setLocalServerModel(MutableComboBoxModel<LocalServer> localServers) {
    localServerComponent.setLocalServerModel(localServers);
}
 
Example 20
Source Project: netbeans   Source File: ConfigurableProjectPanel.java    License: Apache License 2.0 votes vote down vote up
public abstract MutableComboBoxModel<LocalServer> getLocalServerModel(); 
Example 21
Source Project: netbeans   Source File: ConfigurableProjectPanel.java    License: Apache License 2.0 votes vote down vote up
public abstract void setLocalServerModel(MutableComboBoxModel<LocalServer> localServers);