当前位置: 首页>>代码示例>>Java>>正文


Java JComboBox.setSelectedItem方法代码示例

本文整理汇总了Java中javax.swing.JComboBox.setSelectedItem方法的典型用法代码示例。如果您正苦于以下问题:Java JComboBox.setSelectedItem方法的具体用法?Java JComboBox.setSelectedItem怎么用?Java JComboBox.setSelectedItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JComboBox的用法示例。


在下文中一共展示了JComboBox.setSelectedItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getControls

import javax.swing.JComboBox; //导入方法依赖的package包/类
public Component getControls() {
  if (panel == null) {
    panel = Box.createHorizontalBox();
    panel.add(new JLabel(name));
    box = new JComboBox(validValues);
    box.setMaximumSize(new Dimension(box.getMaximumSize().width,box.getPreferredSize().height));
    if (isValidValue(getValue())) {
      box.setSelectedItem(getValue());
    }
    else if (validValues.length > 0) {
      box.setSelectedIndex(0);
    }
    box.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        noUpdate = true;
        setValue(box.getSelectedItem());
        noUpdate = false;
      }
    });
    panel.add(box);
  }
  return panel;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:24,代码来源:StringEnumConfigurer.java

示例2: confirm

import javax.swing.JComboBox; //导入方法依赖的package包/类
public void confirm(EventObject fe) {
    JTextField tf = (JTextField) fe.getSource();
    JComboBox combo = (JComboBox) tf.getParent();
    if (combo==null)
        return;
    if (fe instanceof FocusEvent) {
        combo.getEditor().getEditorComponent().removeFocusListener(this);
    } else {
        combo.getEditor().getEditorComponent().removeKeyListener(this);
    }
    Configuration config = configName==null ? 
            ConfigurationsManager.getDefault().duplicate(lastSelected, tf.getText(), tf.getText()):
            ConfigurationsManager.getDefault().create(tf.getText(), tf.getText());
    combo.setSelectedItem(config);
    combo.setEditable(false);
    currentActiveItem = null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ConfigurationsComboModel.java

示例3: confirm

import javax.swing.JComboBox; //导入方法依赖的package包/类
private void confirm(EventObject fe) {
    JTextField tf = (JTextField) fe.getSource();
    JComboBox combo = (JComboBox) tf.getParent();
    if (combo==null)
        return;
    if (fe instanceof FocusEvent) {
        combo.getEditor().getEditorComponent().removeFocusListener(this);
    } else {
        combo.getEditor().getEditorComponent().removeKeyListener(this);
    }
    Configuration config = configName==null ? 
            ConfigurationsManager.getDefault().duplicate(lastSelected, tf.getText(), tf.getText()):
            ConfigurationsManager.getDefault().create(tf.getText(), tf.getText());
    combo.setSelectedItem(config);
    combo.setEditable(false);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:ConfigurationsComboModel.java

示例4: addChoice

import javax.swing.JComboBox; //导入方法依赖的package包/类
/** Create a choice menu.
 *  @param name The name used to identify the entry (when calling get).
 *  @param label The label to attach to the entry.
 *  @param values The list of possible choices.
 *  @param defaultChoice Default choice.
 *  @param editable True if an arbitrary choice can be entered, in addition
 *   to the choices in values.
 *  @param background The background color for the editable part.
 */
public void addChoice(
        String name,
        String label,
        String[] values,
        String defaultChoice,
        boolean editable,
        Color background) {
    JLabel lbl = new JLabel(label + ": ");
    lbl.setBackground(_background);
    JComboBox combobox = new JComboBox(values);
    combobox.setEditable(editable);
    // FIXME: Typical of Swing, the following does not set
    // the background color.  How does one set the background
    // color?
    combobox.setBackground(background);
    combobox.setSelectedItem(defaultChoice);
    _addPair(name, lbl, combobox, combobox);
    // Add the listener last so that there is no notification
    // of the first value.
    combobox.addItemListener(new QueryItemListener(name));
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:31,代码来源:Query.java

示例5: selectInCombo

import javax.swing.JComboBox; //导入方法依赖的package包/类
private boolean selectInCombo(JComboBox combo, Object value, boolean forceInModel) {
    if (value == null) {
        return false;
    }
    if (!value.equals(combo.getSelectedItem())) {
        combo.setSelectedItem(value);
    } 
    if (forceInModel && !value.equals("") && !value.equals(combo.getSelectedItem())) { // NOI18N
        // Reload of server attributes is needed - workarounding it
        ComboBoxModel model = combo.getModel();
        if (model instanceof DefaultComboBoxModel) {
            ((DefaultComboBoxModel)model).insertElementAt(value, 0);
            combo.setSelectedIndex(0);
        }
    }
    return value.equals(combo.getSelectedItem());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:IssuePanel.java

示例6: bindMatchTypeComboBox

import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
 * Bind Match Type option to a combo box.
 *
 * @param comboBox Combo box to control and display the match type. The
 * model of the combo box can contain only items of type {@link MatchType}.
 * {@link MatchType#LITERAL} and {@link MatchType#REGEXP} are mandatory in
 * the model.
 *
 * @since api.search/1.11
 */
public void bindMatchTypeComboBox(@NonNull final JComboBox comboBox) {
    Parameters.notNull("comboBox", comboBox);                       //NOI18N

    boolean regexpFound = false, literalFound = false;
    for (int i = 0; i < comboBox.getItemCount(); i++) {
        if (comboBox.getItemAt(i) == MatchType.LITERAL) {
            literalFound = true;
        } else if (comboBox.getItemAt(i) == MatchType.REGEXP) {
            regexpFound = true;
        } else if (!(comboBox.getItemAt(i) instanceof MatchType)) {
            throw new IllegalArgumentException("Model of the combo "//NOI18N
                    + "box can contain only MatchType items");      //NOI18N
        }
    }
    if (!(regexpFound && literalFound)) {
        throw new IllegalArgumentException(
                "At least MatchType.LITERAL and MatchType.REGEXP " //NOI18N
                + "must be contained in the combo box model.");     //NOI18N
    }
    if (matchTypeComboBox != null) {
        throw new IllegalStateException(
                "Already bound with option MATCH_TYPE");            //NOI18N
    }
    this.matchTypeComboBox = comboBox;
    comboBox.setEditable(false);
    setMatchType(this.matchType); //update match type, check it is supported
    comboBox.setSelectedItem(matchType);
    comboBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            setMatchType((MatchType) comboBox.getSelectedItem());
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:45,代码来源:SearchPatternController.java

示例7: createComboBox

import javax.swing.JComboBox; //导入方法依赖的package包/类
private JComboBox createComboBox(CandidateDescription[] choices, CandidateDescription defaultValue, Font font, FocusListener listener ) {
    JComboBox combo = new JComboBox(choices);
    combo.setSelectedItem(defaultValue);
    combo.getAccessibleContext().setAccessibleDescription(getBundleString("FixDupImportStmts_Combo_ACSD")); //NOI18N
    combo.getAccessibleContext().setAccessibleName(getBundleString("FixDupImportStmts_Combo_Name_ACSD")); //NOI18N
    combo.setOpaque(false);
    combo.setFont( font );
    combo.addFocusListener( listener );
    combo.setEnabled( choices.length > 1 );
    combo.setRenderer( new DelegatingRenderer(combo.getRenderer()));
    InputMap inputMap = combo.getInputMap( JComboBox.WHEN_FOCUSED );
    inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_SPACE, 0), "showPopup" ); //NOI18N
    combo.getActionMap().put( "showPopup", new TogglePopupAction() ); //NOI18N
    return combo;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:FixDuplicateImportStmts.java

示例8: createPortNameCombo

import javax.swing.JComboBox; //导入方法依赖的package包/类
private JComboBox<String> createPortNameCombo() {
    final JComboBox <String> ret = new JComboBox<>( new SerialPortComboModel(model) );
    ret.addItemListener( (e) -> {            
        if ( e.getStateChange() == ItemEvent.SELECTED ) {
            model.setCurrentPortName( e.getItem().toString() );
        } else {
            model.setCurrentPortName( null );
        }
    });
    ret.setSelectedItem( model.getCurrentPortName() );
    return ret;
}
 
开发者ID:chipKIT32,项目名称:chipKIT-importer,代码行数:13,代码来源:SerialMonitorConfigPane.java

示例9: initGapValues

import javax.swing.JComboBox; //导入方法依赖的package包/类
private static void initGapValues(EditableGap eg, JComboBox sizeCombo, JCheckBox resCheckBox) {
    if (eg != null) {
        String selected = null;
        String[] defaultNames = eg.getPaddingDisplayNames();
        if (eg.canHaveDefaultValue() && defaultNames != null) {
            sizeCombo.setModel(new DefaultComboBoxModel(defaultNames));
            if (eg.definedSize == LayoutConstants.NOT_EXPLICITLY_DEFINED) {
                LayoutConstants.PaddingType[] defaultTypes = eg.getPossiblePaddingTypes();
                if (eg.paddingType == null || defaultTypes == null || defaultTypes.length == 0) {
                    selected = defaultNames[0];
                } else {
                    for (int i=0; i < defaultTypes.length; i++) {
                        if (eg.paddingType == defaultTypes[i]) {
                            selected = defaultNames[i];
                            break;
                        }
                    }
                }
            }
        }
        if (selected == null) {
            selected = Integer.toString(eg.definedSize);
        }
        sizeCombo.setSelectedItem(selected);

        resCheckBox.setSelected(eg.resizing);
    } else {
        sizeCombo.setSelectedItem(NbBundle.getMessage(EditLayoutSpacePanel.class, "VALUE_NoEmptySpace")); // NOI18N
        sizeCombo.setEnabled(false);
        resCheckBox.setEnabled(false);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:EditLayoutSpacePanel.java

示例10: setSelected

import javax.swing.JComboBox; //导入方法依赖的package包/类
static void setSelected(JComboBox<?> combo, Object value) {
	for (int i = combo.getItemCount() - 1; i >= 0; i--) {
		ComboOption opt = (ComboOption) combo.getItemAt(i);
		if (opt.getValue().equals(value)) {
			combo.setSelectedItem(opt);
			return;
		}
	}
	combo.setSelectedItem(combo.getItemAt(0));
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:11,代码来源:ComboOption.java

示例11: initializeCombo

import javax.swing.JComboBox; //导入方法依赖的package包/类
private void initializeCombo() {
    boolean hasExistingRepositories = (existingRepositories != null)
                                      && (existingRepositories.length != 0);
    boolean hasBugtrackingConnectors = (bugtrackingConnectors != null)
                                       && (bugtrackingConnectors.length != 0);

    if (!hasExistingRepositories && !hasBugtrackingConnectors) {
        throw new IllegalStateException("No data for the combo-box."); //NOI18N
    }

    String newConnectionFormatString
                = (bugtrackingConnectorDisplayFormat != null)
                  ? bugtrackingConnectorDisplayFormat
                  : NbBundle.getMessage(
                            ComboItemsRenderer.class,
                            "NewBugtrackingRepositoryConnection");  //NOI18N

    combo = new JComboBox(joinArrays(existingRepositories,
                                     createRepositoryInfos(bugtrackingConnectors)));
    combo.setRenderer(new ComboItemsRenderer(combo.getRenderer(),
                                             newConnectionFormatString));
    //combo.setEditable(false);

    if (repoToPreselect != null) {
        combo.setSelectedItem(repoToPreselect);
    }
    itemSelected(combo.getSelectedItem());
    combo.addItemListener(this);
    combo.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(RepositorySelectorBuilder.class, "RepositorySelectorBuilder.combo.accessibleDescription")); // NOI18N

    if (label != null) {
        bindLabelToCombo();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:RepositorySelectorBuilder.java

示例12: populateTypeComboBox

import javax.swing.JComboBox; //导入方法依赖的package包/类
public void populateTypeComboBox(JComboBox comboBox) {

		ArrayList<VariationFunctionContext> typeList;

		typeList = this.variationFunctionContextList;
		for (VariationFunctionContext context : typeList) {
			comboBox.addItem(context);
		}

		comboBox.setSelectedItem(this.defaultVariationFunctionContext);
	}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:12,代码来源:VariationPerParameterTableController.java

示例13: setSelected

import javax.swing.JComboBox; //导入方法依赖的package包/类
static <Option> void setSelected(JComboBox<Option> combo, Object value) {
	for (int i = combo.getItemCount() - 1; i >= 0; i--) {
		PrefOption opt = (PrefOption) combo.getItemAt(i);
		if (opt.getValue().equals(value)) {
			combo.setSelectedItem(opt);
			return;
		}
	}
	combo.setSelectedItem(combo.getItemAt(0));
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:11,代码来源:PrefOption.java

示例14: setComboValue

import javax.swing.JComboBox; //导入方法依赖的package包/类
@Messages("HINT_inherited=Value is inherited from parent POM.")
    private void setComboValue(T value, T projectValue, JComboBox field) {
        if (!Utilities.compareObjects(value, projectValue)) {
            field.setSelectedItem(value != null ? value : field.getModel().getElementAt(0));
            component.setToolTipText(null);
            inherited = false;
            label.setFont(label.getFont().deriveFont(Font.BOLD));
        } else {
            field.setSelectedItem(projectValue != null ? projectValue : field.getModel().getElementAt(0));
//            field.setBackground(INHERITED);
            label.setFont(label.getFont().deriveFont(Font.PLAIN));
            component.setToolTipText(HINT_inherited());
            inherited = true;
      }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:ComboBoxUpdater.java

示例15: setColor

import javax.swing.JComboBox; //导入方法依赖的package包/类
static void setColor (JComboBox<ColorValue> combo, Color color) {
    if (color == null) {
        combo.setSelectedIndex (content.length - 1);
    } else {
        combo.setSelectedItem (new ColorValue (color));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:ColorComboBox.java


注:本文中的javax.swing.JComboBox.setSelectedItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。