Java Code Examples for javax.swing.JComboBox#setSelectedItem()

The following examples show how to use javax.swing.JComboBox#setSelectedItem() . 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 File: ParametersPanel.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example 2
Source File: XgappUpgradeSelector.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: QueryEditorPanel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
    }
  }
}
 
Example 4
Source File: InsnEditDialogue.java    From JByteMod-Beta with GNU General Public License v2.0 6 votes vote down vote up
@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));
  }
}
 
Example 5
Source File: AbstractLoginHandler.java    From ib-controller with GNU General Public License v3.0 6 votes vote down vote up
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");
            }
        }
    }
}
 
Example 6
Source File: ProfileBaseForm.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void setCombo(JComboBox combo, String item) {
    if (item == null) {
        combo.setSelectedIndex(0);
    } else {
        combo.setSelectedItem(item);
    }
}
 
Example 7
Source File: PrefOption.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
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));
}
 
Example 8
Source File: EditLayoutSpacePanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 9
Source File: SkillEditor.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
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;
}
 
Example 10
Source File: XgappUpgradeSelector.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 11
Source File: ConfigurationsComboModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 12
Source File: ConfigurationsComboModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 13
Source File: ConfirmDeclarationDialog.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 14
Source File: ConfigurationsComboModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 15
Source File: MediaFormatWnd.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
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);
	}
}
 
Example 16
Source File: ComponentController.java    From swingsane with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 17
Source File: QueryWindow.java    From bboxdb with Apache License 2.0 4 votes vote down vote up
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;
	}
 
Example 18
Source File: Assistant.java    From Dayon with GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example 19
Source File: PlacePanel.java    From iBioSim with Apache License 2.0 4 votes vote down vote up
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);
	}
}
 
Example 20
Source File: SettingsDialog.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * <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;
}