javax.swing.JComboBox#setSelectedItem ( )源码实例Demo

下面列出了javax.swing.JComboBox#setSelectedItem ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ib-controller   文件: AbstractLoginHandler.java
protected final void setTradingModeCombo(final Window window) {
    if (SwingUtils.findLabel(window, "Trading Mode") != null)  {
        JComboBox<?> tradingModeCombo;
        if (Settings.settings().getBoolean("FIX", false)) {
            tradingModeCombo = SwingUtils.findComboBox(window, 1);
        } else {
            tradingModeCombo = SwingUtils.findComboBox(window, 0);
        }
        
        if (tradingModeCombo != null ) {
            String tradingMode = TradingModeManager.tradingModeManager().getTradingMode();
            Utils.logToConsole("Setting Trading mode = " + tradingMode);
            if (tradingMode.equalsIgnoreCase(TradingModeManager.TRADING_MODE_LIVE)) {
                tradingModeCombo.setSelectedItem("Live Trading");
            } else {
                tradingModeCombo.setSelectedItem("Paper Trading");
            }
        }
    }
}
 
源代码2 项目: gate-core   文件: XgappUpgradeSelector.java
@Override
@SuppressWarnings("unchecked")
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
  JComboBox<UpgradeXGAPP.UpgradePath.UpgradeStrategy> combo = (JComboBox)super.getTableCellEditorComponent(table, value, isSelected, row, column);
  DefaultComboBoxModel<UpgradeXGAPP.UpgradePath.UpgradeStrategy> model = (DefaultComboBoxModel)combo.getModel();
  model.removeAllElements();
  if(((String)table.getValueAt(row, 0)).startsWith("<html>")) {
    // directory plugin
    model.addElement(UpgradeXGAPP.UpgradePath.UpgradeStrategy.UPGRADE);
    model.addElement(UpgradeXGAPP.UpgradePath.UpgradeStrategy.PLUGIN_ONLY);
    model.addElement(UpgradeXGAPP.UpgradePath.UpgradeStrategy.SKIP);
  } else {
    // old $gatehome$ or existing Maven
    model.addElement(UpgradeXGAPP.UpgradePath.UpgradeStrategy.UPGRADE);
    model.addElement(UpgradeXGAPP.UpgradePath.UpgradeStrategy.SKIP);
  }
  combo.setSelectedItem(value); // which must be one of the available ones
  return combo;
}
 
源代码3 项目: JByteMod-Beta   文件: InsnEditDialogue.java
@Override
protected void addSpecialInputs(Object obj, JPanel leftText, JPanel rightInput) {
  if (obj instanceof AbstractInsnNode) {
    AbstractInsnNode ain = (AbstractInsnNode) obj;
    String[] arr = opc.get(ain.getClass().getSimpleName());
    if (arr != null) {
      leftText.add(new JLabel("Opcode: "));
      JComboBox<String> opcode = new JComboBox<String>(arr);
      opcode.setSelectedItem(OpUtils.getOpcodeText(ain.getOpcode()).toLowerCase());
      rightInput.add(wrap("opc", opcode));
    }
  }
  if (obj instanceof FrameNode) {
    FrameNode fn = (FrameNode) obj;
    leftText.add(new JLabel("Local / Stack: "));
    JButton edit = new JButton(JByteMod.res.getResource("edit"));
    edit.addActionListener(e -> {
      new JFrameList(fn.local, fn.stack).open();
    });
    rightInput.add(wrap("editframe", edit));
  }
}
 
源代码4 项目: pentaho-reporting   文件: QueryEditorPanel.java
protected void setScriptingLanguage( final String lang, final JComboBox languageField ) {
  if ( lang == null ) {
    languageField.setSelectedItem( null );
    return;
  }

  final ListModel model = languageField.getModel();
  for ( int i = 0; i < model.getSize(); i++ ) {
    final ScriptEngineFactory elementAt = (ScriptEngineFactory) model.getElementAt( i );
    if ( elementAt == null ) {
      continue;
    }
    if ( elementAt.getNames().contains( lang ) ) {
      languageField.setSelectedItem( elementAt );
      return;
    }
  }
}
 
源代码5 项目: hortonmachine   文件: ParametersPanel.java
private void handleComboField( FieldData inputField, int row, int col, CellConstraints cc ) {
    String[] guiHintsSplit = inputField.guiHints.split(";");
    String[] imtemsSplit = new String[]{" - "};
    for( String guiHint : guiHintsSplit ) {
        if (guiHint.startsWith(HMConstants.COMBO_UI_HINT)) {
            String items = guiHint.replaceFirst(HMConstants.COMBO_UI_HINT, "").replaceFirst(":", "").trim();
            imtemsSplit = items.split(",");
            break;
        }
    }
    JComboBox<String> comboBox = new JComboBox<String>(imtemsSplit);
    this.add(comboBox, cc.xy(col, row));
    fieldName2ValueHolderMap.put(inputField.fieldName, comboBox);

    if (inputField.fieldValue.length() > 0) {
        comboBox.setSelectedItem(inputField.fieldValue);
    }
}
 
源代码6 项目: swingsane   文件: ComponentController.java
private void updateResolutionModel(ComboBoxModel<Integer> resolutionModel, Integer resolution) {
  JComboBox<Integer> resolutionComboBox = components.getResolutionComboBox();
  resolutionComboBox.setModel(resolutionModel != null ? resolutionModel
      : new DefaultComboBoxModel<Integer>());
  resolutionComboBox.setEnabled(resolutionModel != null ? true : false);
  if (resolutionModel != null) {
    resolutionComboBox.setSelectedItem(resolution);
  }
}
 
源代码7 项目: xdm   文件: MediaFormatWnd.java
private void addToModel(DefaultComboBoxModel<String> model, List<String> list, String defaultValue,
		JComboBox<String> cmb) {
	model.removeAllElements();
	if (list == null) {
		return;
	}
	for (String s : list) {
		model.addElement(s);
	}
	if (!StringUtils.isNullOrEmptyOrBlank(defaultValue)) {
		cmb.setSelectedItem(defaultValue);
	}
}
 
源代码8 项目: netbeans   文件: ConfigurationsComboModel.java
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 = lastSelected;
    config.setDisplayName(tf.getText());
    combo.setSelectedItem(config);
    combo.setEditable(false);
}
 
源代码9 项目: freecol   文件: ConfirmDeclarationDialog.java
private <T> void addComboBox(JPanel panel, JComboBox<T> box,
                             String prefix, T value) {
    box.setRenderer(new EnumRenderer<T>(prefix));
    box.setSelectedItem(value);
    box.addItemListener(this);
    panel.add(Utility.localizedLabel(prefix + "label"));
    panel.add(box);
}
 
源代码10 项目: netbeans   文件: ConfigurationsComboModel.java
@Override
public void actionPerformed(ActionEvent ae) {
    currentActiveItem = this;
    
    JComboBox combo = (JComboBox) ae.getSource();
    combo.setEditable(true);
    JTextField editorComponent = (JTextField) combo.getEditor().getEditorComponent();
    editorComponent.addFocusListener(this);
    editorComponent.addKeyListener(this);
    combo.setSelectedItem(lastSelected);
    combo.addPopupMenuListener(this);
}
 
源代码11 项目: netbeans   文件: ConfigurationsComboModel.java
@Override
public void actionPerformed(ActionEvent ae) {
    currentActiveItem = this;
    
    JComboBox combo = (JComboBox) ae.getSource();
    combo.setEditable(true);
    combo.getEditor().getEditorComponent().addFocusListener(this);
    combo.getEditor().getEditorComponent().addKeyListener(this);
    combo.addPopupMenuListener(this);
    combo.setSelectedItem(configName == null ? lastSelected + "1" : configName);
}
 
源代码12 项目: netbeans   文件: ProfileBaseForm.java
protected void setCombo(JComboBox combo, String item) {
    if (item == null) {
        combo.setSelectedIndex(0);
    } else {
        combo.setSelectedItem(item);
    }
}
 
源代码13 项目: gate-core   文件: XgappUpgradeSelector.java
@Override
@SuppressWarnings("unchecked")
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
  JComboBox<Version> combo = (JComboBox<Version>)super.getTableCellEditorComponent(table, value, isSelected, row, column);
  DefaultComboBoxModel<Version> model = (DefaultComboBoxModel<Version>)combo.getModel();
  model.removeAllElements();
  UpgradeXGAPP.UpgradePath path = (UpgradeXGAPP.UpgradePath)table.getValueAt(row, -1);
  for(Version v : path.getVersions()) {
    model.addElement(v);
  }
  combo.setSelectedItem(value); // which must be one of the available ones
  return combo;
}
 
源代码14 项目: gcs   文件: SkillEditor.java
private JComboBox<Object> createComboBox(Container parent, Object[] items, Object selection, String tooltip) {
    JComboBox<Object> combo = new JComboBox<>(items);
    combo.setToolTipText(Text.wrapPlainTextForToolTip(tooltip));
    combo.setSelectedItem(selection);
    combo.addActionListener(this);
    combo.setMaximumRowCount(items.length);
    UIUtilities.setToPreferredSizeOnly(combo);
    combo.setEnabled(mIsEditable);
    parent.add(combo);
    return combo;
}
 
源代码15 项目: netbeans   文件: EditLayoutSpacePanel.java
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);
    }
}
 
源代码16 项目: Logisim   文件: PrefOption.java
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));
}
 
源代码17 项目: iBioSim   文件: PlacePanel.java
public PlacePanel(String selected, PropertyList placeList, PropertyList controlList,
		LPN lhpn) {
	super(new GridLayout(2, 1));
	this.selected = selected;
	this.placeList = placeList;
	this.controlList = controlList;
	this.lhpn = lhpn;

	fields = new HashMap<String, PropertyField>();

	// ID field
	PropertyField field = new PropertyField(GlobalConstants.ID, "", null, null,
			Utility.ATACSIDstring);
	fields.put(GlobalConstants.ID, field);
	add(field);

	// Initial field
	JPanel tempPanel = new JPanel();
	JLabel tempLabel = new JLabel("Initially Marked");
	initBox = new JComboBox(initCond);
	initBox.setSelectedItem(initCond[1]);
	initBox.addActionListener(this);
	tempPanel.setLayout(new GridLayout(1, 2));
	tempPanel.add(tempLabel);
	tempPanel.add(initBox);
	add(tempPanel);
	
	

	String oldName = null;
	if (selected != null) {
		oldName = selected;
		// Properties prop = lhpn.getVariables().get(selected);
		fields.get(GlobalConstants.ID).setValue(selected);
		if (lhpn.getPlace(selected).isMarked()) {
			initBox.setSelectedItem(initCond[0]);
		}
		else {
			initBox.setSelectedItem(initCond[1]);
		}
	}

	boolean display = false;
	while (!display) {
		display = openGui(oldName);
	}
}
 
源代码18 项目: bboxdb   文件: QueryWindow.java
private PanelBuilder buildDialog() {

		final FormLayout layout = new FormLayout(
			    "right:pref, 3dlu, 100dlu, 10dlu, right:pref, 3dlu, 100dlu", 			// columns
			    "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 9dlu, p");	// rows
		
		final PanelBuilder builder = new PanelBuilder(layout);
		builder.setDefaultDialogBorder();
		
		final List<String> allTables = guimodel.getAllTables();
		final String[] allTableArray = allTables.toArray(new String[0]);
		
		final CellConstraints cc = new CellConstraints();
		builder.addSeparator("Query", cc.xyw(1,  1, 3));
		builder.addLabel("Type", cc.xy (1,  3));
		final String[] queries = new String[] {QUERY_NONE, QUERY_RANGE, QUERY_JOIN, 
				QUERY_RANGE_CONTINUOUS, QUERY_JOIN_CONTINUOUS};
		final JComboBox<String> queryTypeBox = new JComboBox<>(queries);
		builder.add(queryTypeBox, cc.xy (3,  3));
		
		builder.addLabel("Table 1", cc.xy (1,  5));
		final JComboBox<String> table1Field = new JComboBox<>(allTableArray);
		table1Field.setEnabled(false);
		builder.add(table1Field, cc.xy (3,  5));
		
		builder.addLabel("Color for table 1", cc.xy (1,  7));		
		final JComboBox<String> table1ColorField = new JComboBox<>(COLOR_NAMES);
		table1ColorField.setSelectedItem(COLOR_NAMES[0]);
		table1ColorField.setEnabled(false);
		builder.add(table1ColorField, cc.xy (3,  7));

		builder.addLabel("Table 2", cc.xy (1,  9));
		final JComboBox<String> table2Field = new JComboBox<>(allTableArray);
		table2Field.setEnabled(false);
		builder.add(table2Field, cc.xy (3,  9));
		
		builder.addLabel("Color for table 2", cc.xy (1,  11));
		final JComboBox<String> table2ColorField = new JComboBox<>(COLOR_NAMES);
		table2ColorField.setSelectedItem(COLOR_NAMES[1]);
		table2ColorField.setEnabled(false);
		builder.add(table2ColorField, cc.xy (3, 11));
		
		builder.addSeparator("Parameter", cc.xyw(5,  1, 3));
		
		builder.addLabel("Longitude begin", cc.xy (5,  3));
		final JTextField longBegin = new JTextField();
		longBegin.setText(selectedLongBegin);
		builder.add(longBegin, cc.xy (7,  3));
		
		builder.addLabel("Longitude end", cc.xy (5,  5));
		final JTextField longEnd = new JTextField();
		longEnd.setText(selectedLongEnd);
		builder.add(longEnd, cc.xy (7,  5));
		
		builder.addLabel("Latitude begin", cc.xy (5,  7));
		final JTextField latBegin = new JTextField();
		latBegin.setText(selectedLatBegin);
		builder.add(latBegin, cc.xy (7,  7));
		
		builder.addLabel("Latitude end", cc.xy (5,  9));
		final JTextField latEnd = new JTextField();
		latEnd.setText(selectedLatEnd);
		builder.add(latEnd, cc.xy (7,  9));

		builder.addLabel("UDF Name", cc.xy (5,  11));
		final JTextField udfNameField = new JTextField();
		builder.add(udfNameField, cc.xy (7,  11));

		builder.addLabel("UDF Value", cc.xy (5,  13));
		final JTextField udfValueField = new JTextField();
		builder.add(udfValueField, cc.xy (7,  13));

		// Close
		final JButton closeButton = new JButton();
		closeButton.setText("Close");
		closeButton.addActionListener((e) -> {
			mainframe.dispose();
		});
		
		final Action executeAction = getExecuteAction(queryTypeBox, 
				table1Field, table1ColorField, table2Field, table2ColorField, 
				longBegin, longEnd, latBegin, latEnd, udfNameField, udfValueField);
		
		final JButton executeButton = new JButton(executeAction);
		executeButton.setText("Execute");
		executeButton.setEnabled(false);
		
		addActionListener(queryTypeBox, table1Field,  table1ColorField, table2Field, 
				table2ColorField, executeButton, udfNameField, udfValueField);

		builder.add(closeButton, cc.xy(5, 17));
		builder.add(executeButton, cc.xy(7, 17));
		
		return builder;
	}
 
源代码19 项目: Dayon   文件: Assistant.java
private Action createComressionConfigurationAction() {
    final Action configure = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent ev) {
            JFrame compressionFrame = (JFrame) SwingUtilities.getRoot((Component) ev.getSource());

            final JPanel pane = new JPanel();
            pane.setLayout(new GridLayout(4, 2, 10, 10));

            final JLabel methodLbl = new JLabel(Babylon.translate("compression.method"));
            // testing only: final JComboBox<CompressionMethod> methodCb = new JComboBox<>(CompressionMethod.values());
            final JComboBox<CompressionMethod> methodCb = new JComboBox<>(Stream.of(CompressionMethod.values()).filter(e -> !e.equals(CompressionMethod.NONE)).toArray(CompressionMethod[]::new));
            methodCb.setSelectedItem(compressorEngineConfiguration.getMethod());

            pane.add(methodLbl);
            pane.add(methodCb);

            final JLabel useCacheLbl = new JLabel(Babylon.translate("compression.cache.usage"));
            final JCheckBox useCacheCb = new JCheckBox();
            useCacheCb.setSelected(compressorEngineConfiguration.useCache());

            pane.add(useCacheLbl);
            pane.add(useCacheCb);

            final JLabel maxSizeLbl = new JLabel(Babylon.translate("compression.cache.max"));
            maxSizeLbl.setToolTipText(Babylon.translate("compression.cache.max.tooltip"));
            final JTextField maxSizeTf = new JTextField(String.valueOf(compressorEngineConfiguration.getCacheMaxSize()));

            pane.add(maxSizeLbl);
            pane.add(maxSizeTf);

            final JLabel purgeSizeLbl = new JLabel(Babylon.translate("compression.cache.purge"));
            purgeSizeLbl.setToolTipText(Babylon.translate("compression.cache.purge.tooltip"));
            final JTextField purgeSizeTf = new JTextField(String.valueOf(compressorEngineConfiguration.getCachePurgeSize()));

            pane.add(purgeSizeLbl);
            pane.add(purgeSizeTf);

            useCacheCb.addActionListener(ev1 -> {
                maxSizeLbl.setEnabled(useCacheCb.isSelected());
                maxSizeTf.setEnabled(useCacheCb.isSelected());
                purgeSizeLbl.setEnabled(useCacheCb.isSelected());
                purgeSizeTf.setEnabled(useCacheCb.isSelected());
            });

            maxSizeLbl.setEnabled(useCacheCb.isSelected());
            maxSizeTf.setEnabled(useCacheCb.isSelected());
            purgeSizeLbl.setEnabled(useCacheCb.isSelected());
            purgeSizeTf.setEnabled(useCacheCb.isSelected());

            final boolean ok = DialogFactory.showOkCancel(compressionFrame, Babylon.translate("compression.settings"), pane, () -> {
                final String max = maxSizeTf.getText();
                if (max.isEmpty()) {
                    return Babylon.translate("compression.cache.max.msg1");
                }

                final int maxValue;

                try {
                    maxValue = Integer.parseInt(max);
                } catch (NumberFormatException ex) {
                    return Babylon.translate("compression.cache.max.msg2");
                }

                if (maxValue <= 0) {
                    return Babylon.translate("compression.cache.max.msg3");
                }

                return validatePurgeValue(purgeSizeTf, maxValue);
            });

            if (ok) {
                final CompressorEngineConfiguration newCompressorEngineConfiguration = new CompressorEngineConfiguration((CompressionMethod) methodCb.getSelectedItem(),
                        useCacheCb.isSelected(), Integer.parseInt(maxSizeTf.getText()), Integer.parseInt(purgeSizeTf.getText()));

                if (!newCompressorEngineConfiguration.equals(compressorEngineConfiguration)) {
                    compressorEngineConfiguration = newCompressorEngineConfiguration;
                    compressorEngineConfiguration.persist();

                    sendCompressorConfiguration(compressorEngineConfiguration);
                }
            }
        }
    };

    configure.putValue(Action.NAME, "configureCompression");
    configure.putValue(Action.SHORT_DESCRIPTION, Babylon.translate("compression.settings.msg"));
    configure.putValue(Action.SMALL_ICON, ImageUtilities.getOrCreateIcon(ImageNames.COMPRESSION_SETTINGS));

    return configure;
}
 
源代码20 项目: MikuMikuStudio   文件: SettingsDialog.java
/**
 * <code>setUpRendererChooser</code> sets the list of available renderers.
 * Data is obtained from the <code>DisplaySystem</code> class. The
 * renderer specified by GameSettings is used as the default value.
 * 
 * @return the list of renderers.
 */
private JComboBox setUpRendererChooser() {
    String modes[] = {"NULL", "JOGL-OpenGL1", "LWJGL-OpenGL2", "LWJGL-OpenGL3", "LWJGL-OpenGL3.1"};
    JComboBox nameBox = new JComboBox(modes);
    nameBox.setSelectedItem(source.getRenderer());
    return nameBox;
}