javax.swing.JComboBox.setSelectedItem()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(13.5k)|赞(0)|评价(0)|浏览(436)

本文整理了Java中javax.swing.JComboBox.setSelectedItem()方法的一些代码示例,展示了JComboBox.setSelectedItem()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JComboBox.setSelectedItem()方法的具体详情如下:
包路径:javax.swing.JComboBox
类名称:JComboBox
方法名:setSelectedItem

JComboBox.setSelectedItem介绍

暂无

代码示例

代码示例来源:origin: log4j/log4j

protected JComboBox createLogLevelCombo() {
 JComboBox result = new JComboBox();
 Iterator levels = getLogLevels();
 while (levels.hasNext()) {
  result.addItem(levels.next());
 }
 result.setSelectedItem(_leastSevereDisplayedLogLevel);
 result.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
   JComboBox box = (JComboBox) e.getSource();
   LogLevel level = (LogLevel) box.getSelectedItem();
   setLeastSevereDisplayedLogLevel(level);
  }
 });
 result.setMaximumSize(result.getPreferredSize());
 return result;
}

代码示例来源:origin: wiztools/rest-client

void hideMe(final boolean isOk){   
  if(isOk){
    contentType = (String)jcb_content_type.getSelectedItem();
    charset = (String)jcb_charset.getSelectedItem();
    // Fire all listeners:
    for(ContentTypeCharsetChangeListener listener: listeners){
      listener.changed(contentType, charset);
    }
  }
  else{
    jcb_content_type.setSelectedItem(contentType);
    jcb_charset.setSelectedItem(charset);
  }
  setVisible(false);
}

代码示例来源:origin: libgdx/libgdx

private void initializeComponents (BillboardParticleBatch renderer) {
  alignCombo = new JComboBox();
  alignCombo.setModel(new DefaultComboBoxModel(AlignModeWrapper.values()));
  alignCombo.setSelectedItem(getAlignModeWrapper(renderer.getAlignMode()));
  alignCombo.addActionListener(new ActionListener() {
    public void actionPerformed (ActionEvent event) {
  sortCombo = new JComboBox();
  sortCombo.setModel(new DefaultComboBoxModel(SortMode.values()));
  sortCombo.setSelectedItem(getSortMode(renderer.getSorter()));
  sortCombo.addActionListener(new ActionListener() {
    public void actionPerformed (ActionEvent event) {
  contentPanel.add(new JLabel("Align"), new GridBagConstraints(0, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(alignCombo, new GridBagConstraints(1, i++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(new JLabel("Use GPU"), new GridBagConstraints(0, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(useGPUBox, new GridBagConstraints(1, i++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(new JLabel("Sort"), new GridBagConstraints(0, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(sortCombo, new GridBagConstraints(1, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,

代码示例来源:origin: log4j/log4j

JLabel label = new JLabel("Filter Level:");
gridbag.setConstraints(label, c);
add(label);
label = new JLabel("Filter Thread:");
gridbag.setConstraints(label, c);
add(label);
label = new JLabel("Filter Logger:");
gridbag.setConstraints(label, c);
add(label);
    Level.TRACE };
final JComboBox priorities = new JComboBox(allPriorities);
final Level lowest = allPriorities[allPriorities.length - 1];
priorities.setSelectedItem(lowest);
aModel.setPriorityFilter(lowest);
gridbag.setConstraints(priorities, c);

代码示例来源:origin: com.googlecode.blaisemath/blaise-graphics

@Override
protected void initCustomizer() {
  combo.addActionListener(new ActionListener(){
    @Override
    public void actionPerformed(ActionEvent e) {
      Class c = (Class) combo.getSelectedItem();
      try {
        setNewValue(c.newInstance());
      } catch (InstantiationException ex) {
        Logger.getLogger(MarkerEditor.class.getName()).log(Level.SEVERE, null, ex);
      } catch (IllegalAccessException ex) {
        Logger.getLogger(MarkerEditor.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  });
  combo.setSelectedItem(getNewValue().getClass());
  panel = new JPanel(new BorderLayout());
  panel.add(combo);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Layout the component
 */
@Override
public void layoutEditor() {
 m_stepToBlockBox.setEditable(true);
 StepManager sm = getStepToEdit().getStepManager();
 List<StepManagerImpl> flowSteps =
  getMainPerspective().getCurrentLayout().getFlow().getSteps();
 for (StepManagerImpl smi : flowSteps) {
  m_stepToBlockBox.addItem(smi.getName());
 }
 JPanel p = new JPanel(new BorderLayout());
 p.setBorder(BorderFactory.createTitledBorder("Choose step to wait for"));
 p.add(m_stepToBlockBox, BorderLayout.NORTH);
 add(p, BorderLayout.CENTER);
 String userSelected = ((Block) getStepToEdit()).getStepToWaitFor();
 if (userSelected != null) {
  m_stepToBlockBox.setSelectedItem(userSelected);
 }
}

代码示例来源:origin: log4j/log4j

protected JToolBar createToolBar() {
 JToolBar tb = new JToolBar();
 tb.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
 JComboBox fontCombo = new JComboBox();
 JComboBox fontSizeCombo = new JComboBox();
 _fontSizeCombo = fontSizeCombo;
  fontCombo.addItem(fonts[j]);
 fontCombo.setSelectedItem(_fontName);
 fontSizeCombo.addItem("8");
 fontSizeCombo.addItem("9");
 fontSizeCombo.addItem("10");
 fontSizeCombo.addItem("12");
 fontSizeCombo.addItem("24");
 fontSizeCombo.setSelectedItem(String.valueOf(_fontSize));
 fontSizeCombo.addActionListener(
   new ActionListener() {
 tb.add(new JLabel(" Font: "));
 tb.add(fontCombo);
 tb.add(fontSizeCombo);

代码示例来源:origin: kiegroup/optaplanner

@Override
public void actionPerformed(ActionEvent e) {
  List<Employee> employeeList = nurseRosteringPanel.getSolution().getEmployeeList();
  // Add 1 to array size to add null, which makes the entity unassigned
  JComboBox employeeListField = new JComboBox(
      employeeList.toArray(new Object[employeeList.size() + 1]));
  LabeledComboBoxRenderer.applyToComboBox(employeeListField);
  employeeListField.setSelectedItem(shiftAssignment.getEmployee());
  int result = JOptionPane.showConfirmDialog(EmployeePanel.this.getRootPane(), employeeListField,
      "Select employee", JOptionPane.OK_CANCEL_OPTION);
  if (result == JOptionPane.OK_OPTION) {
    Employee toEmployee = (Employee) employeeListField.getSelectedItem();
    nurseRosteringPanel.moveShiftAssignmentToEmployee(shiftAssignment, toEmployee);
  }
}

代码示例来源:origin: winder/Universal-G-Code-Sender

@Override
synchronized public void restoreDefaults() throws Exception {
  FirmwareUtils.restoreDefaults((String)controllerConfigs.getSelectedItem());
  updatingCombo = true;
  String selected = (String) controllerConfigs.getSelectedItem();
  this.controllerConfigs.removeAllItems();
  for (String item : configFiles.keySet()) {
    this.controllerConfigs.addItem(item);
  }
  controllerConfigs.setSelectedItem(selected);
  updatingCombo = false;
  updateComponentsInternal(settings);
}

代码示例来源:origin: ballerina-platform/ballerina-lang

private JComboBox<String> createComboBox(final JPanel panel, final String selected) {
  final JComboBox<String> typeBox = new ComboBox<>();
  final ConfigurableTypes[] types = ConfigurableTypes.values();
  for (final ConfigurableTypes type : types) {
    typeBox.addItem(type.getTyp());
  }
  typeBox.setSelectedItem(selected);
  typeBox.addItemListener(e -> {
    if (e.getStateChange() == ItemEvent.SELECTED) {
      final int idx = getComponentIndex(panel);
      if (e.getItem().equals(ConfigurableTypes.ARTIFACT.getTyp())) {
        rootPanel.add(createArtifactRow("", "", "", ""), idx);
        rootPanel.remove(panel);
        rows.remove(idx);
      } else if (e.getItem().equals(ConfigurableTypes.RAWCOMMAND.getTyp())) {
        rootPanel.add(createCommandRow("", ""), idx);
        rootPanel.remove(panel);
        rows.remove(idx);
      } else if (e.getItem().equals(ConfigurableTypes.EXE.getTyp())) {
        rootPanel.add(createExeRow("", "", ""), idx);
        rootPanel.remove(panel);
        rows.remove(idx);
      } else {
        LOG.error("Unknown type : " + e.getItem());
      }
    }
  });
  return typeBox;
}

代码示例来源:origin: 4thline/cling

expirationComboBox.setSelectedItem(expiration);
expirationComboBox.setMaximumSize(new Dimension(100, 32));
expirationComboBox.addActionListener(new ActionListener() {
toolBar.add(pauseLabel);
toolBar.add(Box.createHorizontalGlue());
toolBar.add(new JLabel("Clear after:"));
toolBar.add(expirationComboBox);

代码示例来源:origin: nroduit/Weasis

private void addDisplayFormatComponent() {
    formatLabel = new JLabel(Messages.getString("ToolPanel.disp_format") + StringUtil.COLON); //$NON-NLS-1$
    this.add(formatLabel);

    formatCombo = new JComboBox<>(Format.values());
    formatCombo.setFocusable(false);
    formatCombo.setSelectedItem(view.getCurrentFormat());
    formatCombo.addActionListener(e -> view.setFormat((Format) formatCombo.getSelectedItem()));
    this.add(formatCombo);
  }
}

代码示例来源:origin: winterDroid/android-drawable-importer-intellij-plugin

private void updateAlgorithmMethod() {
  methodSpinner.removeActionListener(methodListener);
  methodSpinner.removeAllItems();
  final List<String> methods = controller.getMethods();
  for (String method : methods) {
    methodSpinner.addItem(method);
  }
  methodSpinner.setSelectedItem(controller.getMethod());
  methodSpinner.setEnabled(methods.size() > 1);
  methodSpinner.addActionListener(methodListener);
}

代码示例来源:origin: kiegroup/optaplanner

@Override
public void actionPerformed(ActionEvent e) {
  TspSolution tspSolution = tspPanel.getSolution();
  JComboBox previousStandstillListField = new JComboBox();
  for (Standstill previousStandstill : tspSolution.getVisitList()) {
    previousStandstillListField.addItem(previousStandstill);
  }
  previousStandstillListField.addItem(tspSolution.getDomicile());
  previousStandstillListField.setSelectedItem(visit.getPreviousStandstill());
  int result = JOptionPane.showConfirmDialog(TspListPanel.this.getRootPane(), previousStandstillListField,
      "Visit " + visit.getLocation() + " after", JOptionPane.OK_CANCEL_OPTION);
  if (result == JOptionPane.OK_OPTION) {
    Standstill toStandstill = (Standstill) previousStandstillListField.getSelectedItem();
    tspPanel.doMove(visit, toStandstill);
    tspPanel.getWorkflowFrame().resetScreen();
  }
}

代码示例来源:origin: magefree/mage

uiDialog.getSourcesCombo().setSelectedItem(DownloadSources.SCRYFALL);
selectedSource = ScryfallImageSource.instance;
uiDialog.getSourcesCombo().addItemListener((ItemEvent event) -> {
uiDialog.getLaunguagesCombo().setSelectedItem(PreferencesDialog.getPrefImagesLanguage());
reloadLanguagesForSelectedSource();
      selectedSource.setCurrentLanguage((CardLanguage) uiDialog.getLaunguagesCombo().getSelectedItem());

代码示例来源:origin: stackoverflow.com

f.add(variantPanel("regular"));
f.add(variantPanel("large"));
JPanel customPanel = new JPanel();
customPanel.add(createCustom("One"));
customPanel.add(createCustom("Two"));
JPanel variantPanel = new JPanel();
variantPanel.add(createVariant("One", size));
variantPanel.add(createVariant("Two", size));
  names.add(info.getName());
final JComboBox combo = new JComboBox(names.toArray());
String current = UIManager.getLookAndFeel().getName();
combo.setSelectedItem(current);
combo.addActionListener(new ActionListener() {

代码示例来源:origin: skylot/jadx

JComboBox<EditorTheme> themesCbx = new JComboBox<>(editorThemes);
for (EditorTheme theme : editorThemes) {
  if (theme.getPath().equals(settings.getEditorThemePath())) {
    themesCbx.setSelectedItem(theme);
    break;

代码示例来源:origin: libgdx/libgdx

private void initializeComponents (BillboardParticleBatch renderer) {
  alignCombo = new JComboBox();
  alignCombo.setModel(new DefaultComboBoxModel(AlignModeWrapper.values()));
  alignCombo.setSelectedItem(getAlignModeWrapper(renderer.getAlignMode()));
  alignCombo.addActionListener(new ActionListener() {
    public void actionPerformed (ActionEvent event) {
  sortCombo = new JComboBox();
  sortCombo.setModel(new DefaultComboBoxModel(SortMode.values()));
  sortCombo.setSelectedItem(getSortMode(renderer.getSorter()));
  sortCombo.addActionListener(new ActionListener() {
    public void actionPerformed (ActionEvent event) {
  contentPanel.add(new JLabel("Align"), new GridBagConstraints(0, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(alignCombo, new GridBagConstraints(1, i++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(new JLabel("Use GPU"), new GridBagConstraints(0, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(useGPUBox, new GridBagConstraints(1, i++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(new JLabel("Sort"), new GridBagConstraints(0, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
    new Insets(6, 0, 0, 0), 0, 0));
  contentPanel.add(sortCombo, new GridBagConstraints(1, i, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,

代码示例来源:origin: camunda/camunda-bpm-platform

JLabel label = new JLabel("Filter Level:");
gridbag.setConstraints(label, c);
add(label);
label = new JLabel("Filter Thread:");
gridbag.setConstraints(label, c);
add(label);
label = new JLabel("Filter Logger:");
gridbag.setConstraints(label, c);
add(label);
final JComboBox priorities = new JComboBox(allPriorities);
final Priority lowest = allPriorities[allPriorities.length - 1];
priorities.setSelectedItem(lowest);
aModel.setPriorityFilter(lowest);
gridbag.setConstraints(priorities, c);

代码示例来源:origin: org.apache.jmeter/ApacheJMeter_components

private JPanel createLinePane() {       
  JPanel lineStylePane = new JPanel();
  lineStylePane.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
  lineStylePane.setBorder(BorderFactory.createTitledBorder(
      BorderFactory.createEtchedBorder(),
      JMeterUtils.getResString("graph_resp_time_settings_line"))); // $NON-NLS-1$
  lineStylePane.add(GuiUtils.createLabelCombo(JMeterUtils.getResString("graph_resp_time_stroke_width"), //$NON-NLS-1$
      strokeWidthList));
  strokeWidthList.setSelectedItem(StatGraphProperties.getStrokeWidth()[DEFAULT_STROKE_WIDTH_LIST]);
  lineStylePane.add(GuiUtils.createLabelCombo(JMeterUtils.getResString("graph_resp_time_shape_label"), //$NON-NLS-1$
      pointShapeLine));
  pointShapeLine.setSelectedIndex(DEFAULT_LINE_SHAPE_POINT);
  return lineStylePane;
}

相关文章

JComboBox类方法