Java Code Examples for javax.swing.JComboBox#getSelectedItem()
The following examples show how to use
javax.swing.JComboBox#getSelectedItem() .
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: PaginatorView.java From jdal with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected JComponent buildPanel() { pageSizeCombo = new JComboBox(pageSizes); pageSizeCombo.addItemListener(new PageSizeComboListener()); nextPageButton = new JButton(new NextPageAction()); previousPageButton = new JButton(new PreviousPageAction()); lastPageButton = new JButton(new LastPageAction()); firstPageButton = new JButton(new FirstPageAction()); statusLabel = new JLabel(); countLabel = new JLabel(); JLabel numberPagesLabel = new JLabel(getMessage("PaginatorView.pageSize") + " "); pageSizeCombo.setMaximumSize(new Dimension(70, 30)); numberPagesLabel.setAlignmentX(Container.RIGHT_ALIGNMENT); Box box = Box.createHorizontalBox(); box.setBackground(Color.LIGHT_GRAY); box.setOpaque(true); box.add(countLabel); box.add(Box.createHorizontalStrut( 100 /*180 + numberPagesLabel.getSize().width */)); box.add(Box.createHorizontalGlue()); box.add(firstPageButton); box.add(previousPageButton); box.add(Box.createHorizontalStrut(5)); box.add(statusLabel); box.add(Box.createHorizontalStrut(5)); box.add(nextPageButton); box.add(lastPageButton); box.add(Box.createHorizontalGlue()); box.add(numberPagesLabel); box.add(pageSizeCombo); box.add(Box.createHorizontalStrut(30)); // set page size from combo box String pageSize = (String) pageSizeCombo.getSelectedItem(); paginator.setPageSize(parsePageSize(pageSize)); return box; }
Example 2
Source File: QueryParameterTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testComboParameters() { JComboBox combo = new JComboBox(); ComboParameter cp = new QueryParameter.ComboParameter(combo, PARAMETER, "UTF-8"); assertEquals(PARAMETER, cp.getParameter()); assertNull(combo.getSelectedItem()); assertEquals(cp.get(false).toString(), "&" + PARAMETER + "="); assertFalse(cp.isChanged()); cp.setParameterValues(VALUES); cp.setValues(new ParameterValue[] {PV2}); Object item = combo.getSelectedItem(); assertNotNull(item); assertEquals(PV2, item); ParameterValue[] v = cp.getValues(); assertEquals(1, v.length); assertEquals(PV2, v[0]); assertEquals(cp.get(false).toString(), "&" + PARAMETER + "=" + PV2.getValue()); combo.setSelectedItem(PV3); assertEquals(cp.get(false).toString(), "&" + PARAMETER + "=" + PV3.getValue()); assertTrue(cp.isChanged()); cp.reset(); assertFalse(cp.isChanged()); }
Example 3
Source File: DataComboBoxSupport.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { final JComboBox comboBox = (JComboBox)e.getSource(); Object selectedItem = comboBox.getSelectedItem(); if (selectedItem == NEW_ITEM) { performingNewItemAction = true; try { comboBox.setPopupVisible(false); dataModel.newItemActionPerformed(); } finally { performingNewItemAction = false; } setPreviousNonSpecialItem(comboBox); // we (or maybe the client) have just selected an item inside an actionPerformed event, // which will not send another actionPerformed event for the new item. // We need to make sure all listeners get an event for the new item, // thus... final Object newSelectedItem = comboBox.getSelectedItem(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { comboBox.setSelectedItem(newSelectedItem); } }); } }
Example 4
Source File: CRUDMethodsRESTPanel.java From mobile-persistence with MIT License | 5 votes |
private DCMethod findOrCreateMethod(JTextField methodField, JComboBox requestType) { if (methodField.getText()==null || "".equals(methodField.getText().trim())) { return null; } String fullUri = methodField.getText(); String name = fullUri; int startQueryString = fullUri.indexOf("?"); if (startQueryString>0) { name = fullUri.substring(0,startQueryString); } String methodKey = requestType.getSelectedItem()+": "+name; DCMethod method = methodMap.get(methodKey); if (method==null) { // no method with this URI created yet method = new DCMethod(model.getConnectionName(), fullUri, (String) requestType.getSelectedItem()); // set default header params method.getHeaderParams().addAll(model.getHeaderParams()); methodMap.put(methodKey, method); } method.setRequestType((String) requestType.getSelectedItem()); // We assume that the structure for write methods is same as for findAll method // so we set payloadElementName to and payloadRowElementName (might be null in case of JSON) // to the names stored on the DataObjectInfo when discovering it. // We ONLY do this for new methods, we should preserve the values manually set in persistence-mapping // and we only do this when method is not created through RAML parsing if (!method.isExisting() && !method.isRamlCreated()) { method.setPayloadElementName(getCurrentDataObject().getPayloadListElementName()); method.setPayloadRowElementName(getCurrentDataObject().getPayloadRowElementName()); } return method; }
Example 5
Source File: ColorComboBox.java From netbeans with Apache License 2.0 | 5 votes |
static Color getColor (JComboBox<ColorValue> combo) { // The last item is Inherited Color or None if (combo.getSelectedIndex() < combo.getItemCount() - 1) { return ((ColorValue) combo.getSelectedItem()).color; } else { return null; } }
Example 6
Source File: QuantityNameFilterJPanel.java From opensim-gui with Apache License 2.0 | 5 votes |
private void jModelComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jModelComboBoxActionPerformed // TODO add your handling code here: JComboBox cb = (JComboBox)evt.getSource(); currentModel = (Model) cb.getSelectedItem(); // Find model's muscle groups and fill in drop down' Vector<String> groups=OpenSimDB.getInstance().getModelGuiElements(currentModel).getActuatorGroupNames(); jMuscleGroupComboBox.setModel(new DefaultComboBoxModel(groups)); if (groups.size()>0){ jMuscleGroupComboBox.setSelectedIndex(0); restrictToGroup(groups.get(0)); } }
Example 7
Source File: UI.java From netbeans with Apache License 2.0 | 5 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 8
Source File: SwingAtdl4jInputAndFilterDataPanel.java From atdl4j with MIT License | 5 votes |
public static String getDropDownItemSelected( JComboBox<String> aDropDown ) { String tempText = (String)aDropDown.getSelectedItem(); if ( "".equals( tempText ) ) { return null; } else { return tempText; } }
Example 9
Source File: ScrLexicon.java From PolyGlot with MIT License | 5 votes |
/** * Sets appropriate fields grey */ private void setGreyFields(JComponent comp, String defValue) { if (comp instanceof JComboBox) { JComboBox compCmb = (JComboBox) comp; if (compCmb.getSelectedItem() != null && compCmb.getSelectedItem().toString().equals(defValue)) { compCmb.setForeground(Color.red); } else { compCmb.setForeground(Color.black); } } }
Example 10
Source File: RemoveFunctionsAction.java From ghidra with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionContext context) { MultiFunctionComparisonProvider provider = (MultiFunctionComparisonProvider) context.getComponentProvider(); JComboBox<Function> focusedComponent = ((MultiFunctionComparisonPanel) provider.getComponent()).getFocusedComponent(); Function selectedFunction = (Function) focusedComponent.getSelectedItem(); provider.removeFunctions(new HashSet<>(Arrays.asList(selectedFunction))); provider.contextChanged(); }
Example 11
Source File: SectorColorAttributePlugin.java From ramus with GNU General Public License v3.0 | 4 votes |
@Override public TableCellEditor getTableCellEditor(final Engine engine, final AccessRules rules, final Attribute attribute) { final JComboBox box = new JComboBox(); box.setRenderer(comboBoxRenderer); box.addItem(Color.white); box.addItem(Color.green); box.addItem(Color.blue); box.addItem(Color.red); box.addItem(Color.yellow); box.addItem(Color.cyan); box.addItem(Color.magenta); box.addItem(Color.orange); box.addItem(Color.pink); box.addItem(Color.lightGray); box.addItem(Color.gray); box.addItem(Color.darkGray); box.addItem(Color.black); return new DefaultCellEditor(box) { private Pin pin; @Override public boolean stopCellEditing() { if (box.getSelectedItem() instanceof Color) { ((Journaled) engine).startUserTransaction(); apply((Color) box.getSelectedItem(), pin); return super.stopCellEditing(); } return false; } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { pin = (Pin) ((MetadataGetter) table).getMetadata(); return super.getTableCellEditorComponent(table, value, isSelected, row, column); } }; }
Example 12
Source File: ShapeModelerSetupDialog.java From mzmine2 with GNU General Public License v2.0 | 4 votes |
private void loadPreviewPeak() { PeakListRow previewRow = (PeakListRow) comboPeak.getSelectedItem(); if (previewRow == null) return; logger.finest("Loading new preview peak " + previewRow); Feature previewPeak = previewRow.getPeaks()[0]; ticPlot.removeAllTICDataSets(); // Load the intensities into array RawDataFile dataFile = previewPeak.getDataFile(); int scanNumbers[] = previewPeak.getScanNumbers(); double retentionTimes[] = new double[scanNumbers.length]; for (int i = 0; i < scanNumbers.length; i++) retentionTimes[i] = dataFile.getScan(scanNumbers[i]).getRetentionTime(); double intensities[] = new double[scanNumbers.length]; for (int i = 0; i < scanNumbers.length; i++) { DataPoint dp = previewPeak.getDataPoint(scanNumbers[i]); if (dp != null) intensities[i] = dp.getIntensity(); else intensities[i] = 0; } // Create shape model updateParameterSetFromComponents(); JComboBox<?> component = (JComboBox<?>) getComponentForParameter(ShapeModelerParameters.shapeModelerType); ShapeModel model = (ShapeModel) component.getSelectedItem(); JFormattedTextField resolutionField = (JFormattedTextField) getComponentForParameter(ShapeModelerParameters.massResolution); double resolution = ((Number) resolutionField.getValue()).doubleValue(); try { Class<?> shapeModelClass = model.getModelClass(); Constructor<?> shapeModelConstruct = shapeModelClass.getConstructors()[0]; // shapePeakModel(ChromatographicPeak originalDetectedShape, int[] // scanNumbers, // double[] intensities, double[] retentionTimes, double resolution) Feature shapePeak = (Feature) shapeModelConstruct.newInstance(previewPeak, scanNumbers, intensities, retentionTimes, resolution); PeakDataSet peakDataSet = new PeakDataSet(shapePeak); ticPlot.addPeakDataset(peakDataSet); ticDataset = new ChromatogramTICDataSet(previewRow.getPeaks()[0]); ticPlot.addTICDataset(ticDataset); // Set auto range to axes ticPlot.getXYPlot().getDomainAxis().setAutoRange(true); ticPlot.getXYPlot().getDomainAxis().setAutoTickUnitSelection(true); ticPlot.getXYPlot().getRangeAxis().setAutoRange(true); ticPlot.getXYPlot().getRangeAxis().setAutoTickUnitSelection(true); } catch (Exception e) { String message = "Error trying to make an instance of Peak Builder " + model; MZmineCore.getDesktop().displayErrorMessage(this, message); logger.severe(message); e.printStackTrace(); return; } }
Example 13
Source File: Desktop.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
void doConnect() { final String[] options = new String[Activator.remoteHosts.size()]; Activator.remoteHosts.copyInto(options); // The selection comp I want in the dialog final JComboBox combo = new JComboBox(options); combo.setEditable(true); // Mindboggling complicate way of creating an option dialog // without the auto-generated input field final JLabel msg = new JLabel(Strings.get("remote_connect_msg")); final JPanel panel = new JPanel(new BorderLayout()); panel.add(combo, BorderLayout.SOUTH); panel.add(msg, BorderLayout.NORTH); final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE); optionPane.setIcon(connectIconLarge); optionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION); optionPane.setWantsInput(false); optionPane.setOptions(new String[] { Strings.get("ok"), Strings.get("cancel"), Strings.get("local"), }); optionPane.selectInitialValue(); final JDialog dialog = optionPane.createDialog(frame, Strings.get("remote_connect_title")); dialog.setVisible(true); dialog.dispose(); if (!(optionPane.getValue() instanceof String)) { // We'll get an Integer if // the user pressed Esc return; } final String value = (String) optionPane.getValue(); if (Strings.get("cancel").equals(value)) { return; } String s = (String) combo.getSelectedItem(); if (Strings.get("local").equals(value)) { s = ""; } if (!Activator.remoteHosts.contains(s)) { Activator.remoteHosts.addElement(s); } if ((s != null)) { Activator.openRemote(s); } }
Example 14
Source File: OptionPanel.java From jplag with GNU General Public License v3.0 | 4 votes |
/** * Updates the subdirectory combo box. * The data depends on the following options: * - client.getSubmissionDirectory() * - client.getOptions().getSuffixes() * - client.getOptions().isReadSubdirs() (recurse) */ private void updateSubdirCombo() { updatingSubDirCB = true; JComboBox<String> cb = getJSubdirCB(); String selItem = (String) cb.getSelectedItem(); // will be null, if none selected cb.removeAllItems(); cb.addItem(Messages.getString("OptionPanel.none")); //$NON-NLS-1$ File[] files = (new File(client.getSubmissionDirectory())).listFiles(); if(files == null) { System.out.println("No file found"); System.out.println("Directory: " + jSubmissionDirField.getText()); } genAOSuffixes = getSuffixes(); if(genAOSuffixes != null) { int addedItems = 1, selIndex = 0; for(int i = 0; i < files.length; i++) { if(files[i].isDirectory()) { File[] subfiles = files[i].listFiles(); subfilesloop: for(int j = 0; j < subfiles.length; j++) { if(subfiles[j].isDirectory()) { // Check whether this directory is already in subdircb String dirname = subfiles[j].getName(); for(int k = 0; k < cb.getItemCount(); k++) { if(dirname.equals(cb.getItemAt(k).toString())) continue subfilesloop; // already in combo box } if(hasDirValidFiles(subfiles[j])) { cb.addItem(dirname); if(dirname.equals(selItem)) selIndex = addedItems; addedItems++; } } } } } cb.setSelectedIndex(selIndex); } updatingSubDirCB = false; }
Example 15
Source File: Assistant.java From Dayon with GNU General Public License v3.0 | 4 votes |
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 16
Source File: FmtOptions.java From netbeans with Apache License 2.0 | 4 votes |
private void storeData(JComponent jc, String optionID, Preferences node) { if (jc instanceof JTextField) { JTextField field = (JTextField) jc; String text = field.getText(); // XXX test for numbers if (isInteger(optionID)) { try { Integer.parseInt(text); } catch (NumberFormatException e) { return; } } // XXX: watch out, tabSize, spacesPerTab, indentSize and expandTabToSpaces // fall back on getGlopalXXX() values and not getDefaultAsXXX value, // which is why we must not remove them. Proper solution would be to // store formatting preferences to MimeLookup and not use NbPreferences. // The problem currently is that MimeLookup based Preferences do not support subnodes. if (!optionID.equals(TAB_SIZE) && !optionID.equals(SPACES_PER_TAB) && !optionID.equals(INDENT_SIZE) && getDefaultAsString(optionID).equals(text)) { node.remove(optionID); } else { node.put(optionID, text); } } else if (jc instanceof JCheckBox) { JCheckBox checkBox = (JCheckBox) jc; if (!optionID.equals(EXPAND_TAB_TO_SPACES) && getDefaultAsBoolean(optionID) == checkBox.isSelected()) { node.remove(optionID); } else { node.putBoolean(optionID, checkBox.isSelected()); } } else if (jc instanceof JComboBox) { JComboBox cb = (JComboBox) jc; ComboItem comboItem = ((ComboItem) cb.getSelectedItem()); String value = comboItem == null ? getDefaultAsString(optionID) : comboItem.value; if (getDefaultAsString(optionID).equals(value)) { node.remove(optionID); } else { node.put(optionID, value); } } }
Example 17
Source File: Assistant.java From Dayon with GNU General Public License v3.0 | 4 votes |
private Action createCaptureConfigurationAction() { final Action configure = new AbstractAction() { @Override public void actionPerformed(ActionEvent ev) { JFrame captureFrame = (JFrame) SwingUtilities.getRoot((Component) ev.getSource()); final JPanel pane = new JPanel(); pane.setLayout(new GridLayout(2, 2, 10, 10)); final JLabel tickLbl = new JLabel(Babylon.translate("tick")); tickLbl.setToolTipText(Babylon.translate("tick.tooltip")); final JTextField tickTextField = new JTextField(); tickTextField.setText(String.valueOf(captureEngineConfiguration.getCaptureTick())); pane.add(tickLbl); pane.add(tickTextField); final JLabel grayLevelsLbl = new JLabel(Babylon.translate("grays")); final JComboBox<Gray8Bits> grayLevelsCb = new JComboBox<>(Gray8Bits.values()); grayLevelsCb.setSelectedItem(captureEngineConfiguration.getCaptureQuantization()); pane.add(grayLevelsLbl); pane.add(grayLevelsCb); final boolean ok = DialogFactory.showOkCancel(captureFrame, Babylon.translate("capture.settings"), pane, () -> { final String tick = tickTextField.getText(); if (tick.isEmpty()) { return Babylon.translate("tick.msg1"); } try { Integer.valueOf(tick); } catch (NumberFormatException ex) { return Babylon.translate("tick.msg2"); } return null; }); if (ok) { final CaptureEngineConfiguration newCaptureEngineConfiguration = new CaptureEngineConfiguration(Integer.parseInt(tickTextField.getText()), (Gray8Bits) grayLevelsCb.getSelectedItem()); if (!newCaptureEngineConfiguration.equals(captureEngineConfiguration)) { captureEngineConfiguration = newCaptureEngineConfiguration; captureEngineConfiguration.persist(); sendCaptureConfiguration(captureEngineConfiguration); } } } }; configure.putValue(Action.NAME, "configureCapture"); configure.putValue(Action.SHORT_DESCRIPTION, Babylon.translate("capture.settings.msg")); configure.putValue(Action.SMALL_ICON, ImageUtilities.getOrCreateIcon(ImageNames.CAPTURE_SETTINGS)); return configure; }
Example 18
Source File: BorderEditor.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
private Image getButtonImageBorderIcon(JComboBox b) { return (Image)b.getSelectedItem(); }
Example 19
Source File: ColorComboBox.java From netbeans with Apache License 2.0 | 4 votes |
ComboBoxListener(JComboBox<ColorValue> combo) { this.combo = combo; lastSelection = combo.getSelectedItem(); }
Example 20
Source File: UserInputTypeValidation.java From binnavi with Apache License 2.0 | 4 votes |
/** * Only validate that a base type is selected without showing an error message. */ public static boolean validateComboBox(final JComboBox baseTypes) { return baseTypes.getSelectedItem() != null; }