Java Code Examples for javax.swing.JComboBox.removeAllItems()

The following are Jave code examples for showing how to use removeAllItems() of the javax.swing.JComboBox class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: UI.java   Source Code and License Vote up 7 votes
public static void setItems(JComboBox comboBox, Object[] items) {
    Object selected = comboBox.getSelectedItem();
    comboBox.removeAllItems();

    for (int i = 0; i < items.length; i++) {
        comboBox.insertItemAt(items[i], i);
    }
    if (items.length > 0) {
        comboBox.setSelectedIndex(0);
    }
    if (selected != null) {
        comboBox.setSelectedItem(selected);
    }
}
 
Example 2
Project: Pixie   File: BoundingBoxWindow.java   Source Code and License Vote up 6 votes
/**
 * Create the proper design for the components representing the object
 * attributes and populate the combo boxes with the data defined in the
 * database.
 *
 * @param selectedNode the list of object attributes, including: the list of
 * types, the list of classes, the list of values
 * @param attribute the combo box for which the attribute is initialized
 */
public void initAttributesComponents(CustomTreeNode selectedNode, JComboBox attribute) {
    if (selectedNode == null) {
        return;
    }

    List<String> typeAttrib = selectedNode.getChildren();

    attribute.removeAllItems();

    if ((typeAttrib != null) && (!typeAttrib.isEmpty())) {
        // set the attributes of the combo boxes
        typeAttrib.stream().forEach(objType -> attribute.addItem(Utils.capitalize(objType)));
    }

    attribute.repaint();
}
 
Example 3
Project: incubator-netbeans   File: TargetMappingPanel.java   Source Code and License Vote up 5 votes
private void updateCombos(boolean selectDefaults) {
    // In case you go back and choose a different script:
    Iterator<TargetDescriptor> descriptors = targetDescs.iterator();
    for (JComboBox combo : combos) {
        TargetDescriptor desc = descriptors.next();
        combo.removeAllItems();
        for (String name : targetNames) {
            combo.addItem(name);
        }
        if (selectDefaults) {
            selectItem(combo, desc.getDefaultTargets(), false); // NOI18N
        }
    }
}
 
Example 4
Project: routerapp   File: SpecialGraphWindow.java   Source Code and License Vote up 5 votes
/**
  * Returns the suported Layouts from selected factory 
  */
 public void getSuportedLayouts(JComboBox cb, JComboBox r){
 	Vector layoutOptionsVector = ((GraphFactory)bType.getSelectedItem()).getSupportedLayouts();
 	r.removeAllItems();
/*if(layoutOptionsVector.size()==0)
	layoutOptionsVector.add(new CircleLayout(null));*/
Iterator iterator = layoutOptionsVector.iterator();
Object obj;
while (iterator.hasNext()){
	obj = iterator.next();
	r.addItem(obj);
}
SpecialGraphWindow.getInstance().setVisible(true);
 }
 
Example 5
Project: jmt   File: ParametricAnalysisPanel.java   Source Code and License Vote up 4 votes
public void initGui() {
	enabler = new JCheckBox("Enable What-If analysis");
	enabler.setToolTipText("Enable or disable What-If analysis");
	enablerPanel = new JPanel(new BorderLayout());
	enablerPanel.add(enabler, BorderLayout.WEST);
	upperPanel = new JPanel(new BorderLayout());
	chooserPanel = new JPanel();
	tb = new TitledBorder("Parameter selection for the control of repeated executions");
	chooserPanel.setBorder(tb);
	chooser = new JComboBox(parameters);
	chooser.setPreferredSize(DIM_BUTTON_L);
	chooser.setToolTipText("Choose the what-if analysis to be performed");
	chooserPanel.add(chooser, BorderLayout.NORTH);
	JLabel description = new JLabel(PARAMETRIC_ANALYSIS_DESCRIPTION);
	JLabel Warning = new JLabel (HTML_START + HTML_FONT_TITLE + "WARNING: "+ HTML_FONT_TIT_END + HTML_FONT_NORM
			+ "Enabling What-If analysis will disable all statistical outputs." + HTML_FONT_NOR_END + HTML_END);
	JPanel northPanel = new JPanel(new BorderLayout());
	northPanel.setBorder(new EmptyBorder(0, 0, 15, 0));
	northPanel.add(description, "Center");
	northPanel.add(Warning, "South");
	northPanel.add(enablerPanel, "East");
	upperPanel.add(northPanel, BorderLayout.NORTH);
	upperPanel.add(chooserPanel, BorderLayout.SOUTH);
	this.setLayout(new BorderLayout());
	this.setBorder(new EmptyBorder(20, 20, 20, 20));
	chooser.removeAllItems();
	ParametricAnalysisChecker pac = new ParametricAnalysisChecker(cd, sd, simd);
	if (!pac.canBeEnabled()) {
		enabler.setEnabled(false);
		parameterOptionPanel = createPanel(null);
		simd.setParametricAnalysisModel(null);
		simd.setParametricAnalysisEnabled(false);
	} else {
		enabler.setEnabled(true);
		enabler.setSelected(simd.isParametricAnalysisEnabled());
		ParametricAnalysisDefinition pad = simd.getParametricAnalysisModel();
		parameters = pac.getRunnableParametricAnalysis();
		for (String parameter : parameters) {
			chooser.addItem(parameter);
		}
		String temp = parameters[0];
		if (pad == null) {
			pad = ParametricAnalysisModelFactory.createParametricAnalysisModel(temp, cd, sd, simd);
			simd.setParametricAnalysisModel(pad);
		} else {
			int code = pad.checkCorrectness(true); //check correctness of the PAD and if it is possible corrects it
			if (code != 2) {
				chooser.setSelectedItem(pad.getType());
			} else { //the old type of parametric analysis is no more available
				pad = ParametricAnalysisModelFactory.createParametricAnalysisModel(temp, cd, sd, simd);
				simd.setParametricAnalysisModel(pad);
			}
		}
		parameterOptionPanel = createPanel(pad);
	}
	parameterOptionPanel.setBorder(new EmptyBorder(10, 0, 0, 0));
	this.add(upperPanel, BorderLayout.NORTH);
	this.add(parameterOptionPanel, BorderLayout.CENTER);
	this.setEnabled(enabler.isSelected());
}
 
Example 6
Project: QN-ACTR-Release   File: ParametricAnalysisPanel.java   Source Code and License Vote up 4 votes
public void initGui() {
	enabler = new JCheckBox("Enable what-if analysis");
	enabler.setToolTipText("Enable or disable what-if analysis");
	enablerPanel = new JPanel(new BorderLayout());
	enablerPanel.add(enabler, BorderLayout.WEST);
	//enablerPanel.setBorder(new EmptyBorder(30,10,10,10));
	upperPanel = new JPanel(new BorderLayout());
	chooserPanel = new JPanel();
	tb = new TitledBorder("Parameter selection for the control of repeated executions");
	chooserPanel.setBorder(tb);
	chooser = new JComboBox(parameters);
	chooser.setPreferredSize(DIM_BUTTON_L);
	chooser.setToolTipText("Choose the what-if analysis to be performed");
	chooserPanel.add(chooser, BorderLayout.NORTH);
	JLabel description = new JLabel(PARAMETRIC_ANALYSIS_DESCRIPTION);
	JPanel northPanel = new JPanel(new BorderLayout());
	northPanel.setBorder(new EmptyBorder(0, 0, 15, 0));
	northPanel.add(description, "Center");
	northPanel.add(enablerPanel, "East");
	upperPanel.add(northPanel, BorderLayout.NORTH);
	upperPanel.add(chooserPanel, BorderLayout.SOUTH);
	this.setLayout(new BorderLayout());
	this.setBorder(new EmptyBorder(20, 20, 20, 20));
	chooser.removeAllItems();
	ParametricAnalysisChecker pac = new ParametricAnalysisChecker(cd, sd, simd);
	if (!pac.canBeEnabled()) {
		enabler.setEnabled(false);
		parameterOptionPanel = createPanel(null);
		simd.setParametricAnalysisModel(null);
		simd.setParametricAnalysisEnabled(false);
	} else {
		enabler.setEnabled(true);
		enabler.setSelected(simd.isParametricAnalysisEnabled());
		ParametricAnalysisDefinition pad = simd.getParametricAnalysisModel();
		parameters = pac.getRunnableParametricAnalysis();
		for (String parameter : parameters) {
			chooser.addItem(parameter);
		}
		String temp = parameters[0];
		if (pad == null) {
			pad = ParametricAnalysisModelFactory.createParametricAnalysisModel(temp, cd, sd, simd);
			simd.setParametricAnalysisModel(pad);
		} else {
			int code = pad.checkCorrectness(true); //check correctness of the PAD and if it is possible corrects it
			if (code != 2) {
				chooser.setSelectedItem(pad.getType());
			} else { //the old type of parametric analysis is no more avaible
				pad = ParametricAnalysisModelFactory.createParametricAnalysisModel(temp, cd, sd, simd);
				simd.setParametricAnalysisModel(pad);
			}
		}
		parameterOptionPanel = createPanel(pad);
	}
	parameterOptionPanel.setBorder(new EmptyBorder(10, 0, 0, 0));
	this.add(upperPanel, BorderLayout.NORTH);
	this.add(parameterOptionPanel, BorderLayout.CENTER);
	this.setEnabled(enabler.isSelected());
}