Java Code Examples for javax.swing.JComboBox#getItemCount()
The following examples show how to use
javax.swing.JComboBox#getItemCount() .
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: JComboBoxOperator.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Returns information about component. */ @Override public Hashtable<String, Object> getDump() { Hashtable<String, Object> result = super.getDump(); JComboBox<?> jComboBox = (JComboBox<?>) getSource(); Object selectedItem = jComboBox.getSelectedItem(); if (selectedItem != null) { result.put(TEXT_DPROP, selectedItem.toString()); } int itemCount = jComboBox.getItemCount(); String[] items = new String[itemCount]; for (int i = 0; i < itemCount; i++) { if (jComboBox.getItemAt(i) != null) { items[i] = jComboBox.getItemAt(i).toString(); } } addToDump(result, ITEM_PREFIX_DPROP, items); return result; }
Example 2
Source File: BasicInfoVisualPanel.java From netbeans with Apache License 2.0 | 6 votes |
protected static void initPlatformCombo(JComboBox combo) { if (combo == null){ return; } if (combo.getItemCount() <= 0) { return; } boolean set = false; String idToSelect = ModuleUISettings.getDefault().getLastUsedPlatformID(); for (int i = 0; i < combo.getItemCount(); i++) { if (((NbPlatform) combo.getItemAt(i)).getID().equals(idToSelect)) { combo.setSelectedIndex(i); set = true; break; } } if (!set) { NbPlatform defPlaf = NbPlatform.getDefaultPlatform(); combo.setSelectedItem(defPlaf == null ? combo.getItemAt(0) : defPlaf); } }
Example 3
Source File: WizardUtils.java From netbeans with Apache License 2.0 | 6 votes |
/** * Searches LayerItemPresenter combobox by the item's display name. */ private static String searchLIPCategoryCombo(final JComboBox lpCombo, final String displayName) { String path = null; for (int i = 0; i < lpCombo.getItemCount(); i++) { Object item = lpCombo.getItemAt(i); if (!(item instanceof LayerItemPresenter)) { continue; } LayerItemPresenter presenter = (LayerItemPresenter) lpCombo.getItemAt(i); if (displayName.equals(presenter.getDisplayName())) { path = presenter.getFullPath(); break; } } return path; }
Example 4
Source File: CSSTest.java From netbeans with Apache License 2.0 | 5 votes |
protected List<String> getItems(JComboBoxOperator boxOperator){ JComboBox box = (JComboBox) boxOperator.getSource(); int boxSize = box.getItemCount(); List<String> result = new ArrayList<String>(boxSize); for(int i = 0;i < boxSize; i++){ result.add(box.getModel().getElementAt(i).toString()); } return result; }
Example 5
Source File: JComboBoxBinding.java From magarena with GNU General Public License v3.0 | 5 votes |
public JComboBoxBinding(String property, JComboBox combo, int defaultValue) { if (property == null || combo == null) { throw new NullPointerException(); } if (property.equals("") || combo.getItemCount() == 0 || defaultValue < 0 || defaultValue >= combo.getItemCount()) { throw new IllegalArgumentException(); } _property = property; _combo = combo; _defaultValue = defaultValue; _validColor = combo.getBackground(); }
Example 6
Source File: ParameterValueKeyCellEditor.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
private JComboBox<String> createOperatorCombo(final PropertyTable propertyTable) { List<Operator> allInnerOps = parentOperator.getAllInnerOperators(); Vector<String> allOpNames = new Vector<String>(); Iterator<Operator> i = allInnerOps.iterator(); while (i.hasNext()) { allOpNames.add(i.next().getName()); } Collections.sort(allOpNames); final JComboBox<String> combo = new JComboBox<>(allOpNames); combo.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { String operatorName = (String) combo.getSelectedItem(); panel.remove(parameterCombo); parameterCombo = createParameterCombo(operatorName, propertyTable); panel.add(parameterCombo); fireParameterChangedEvent(); fireEditingStopped(); } }); if (combo.getItemCount() == 0) { combo.addItem("add inner operators"); } else { combo.setSelectedIndex(0); } return combo; }
Example 7
Source File: ComboBoxCellRenderer.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Instantiates a new check box cell renderer. * * @param comboBox the combo box */ public ComboBoxCellRenderer(JComboBox<String> comboBox) { this.combo = new JComboBox<>(); for (int i = 0; i < comboBox.getItemCount(); i++) { combo.addItem(comboBox.getItemAt(i)); } }
Example 8
Source File: ComboOption.java From Logisim with GNU General Public License v3.0 | 5 votes |
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)); }
Example 9
Source File: SelectAmountDialog.java From freecol with GNU General Public License v2.0 | 5 votes |
/** * Verify the contents of the JComboBox. * * @param box The {@code JComboBox} to verify. * @return True if all is well. */ private boolean verifyWholeBox(JComboBox<Integer> box) { final int n = box.getItemCount(); for (int i = 0; i < n; i++) { Integer v = box.getItemAt(i); if (v < 0 || v > available) return false; } return true; }
Example 10
Source File: Example.java From firmata4j with MIT License | 5 votes |
@SuppressWarnings("unchecked") private static String requestPort() { JComboBox<String> portNameSelector = new JComboBox<>(); portNameSelector.setModel(new DefaultComboBoxModel<String>()); String[] portNames; if (SerialNativeInterface.getOsType() == SerialNativeInterface.OS_MAC_OS_X) { // for MAC OS default pattern of jssc library is too restrictive portNames = SerialPortList.getPortNames("/dev/", Pattern.compile("tty\\..*")); } else { portNames = SerialPortList.getPortNames(); } for (String portName : portNames) { portNameSelector.addItem(portName); } if (portNameSelector.getItemCount() == 0) { JOptionPane.showMessageDialog(null, "Cannot find any serial port", "Error", JOptionPane.ERROR_MESSAGE); System.exit(1); } JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); panel.add(new JLabel("Port ")); panel.add(portNameSelector); if (JOptionPane.showConfirmDialog(null, panel, "Select the port", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { return portNameSelector.getSelectedItem().toString(); } else { System.exit(0); } return ""; }
Example 11
Source File: OpendapAccessPanel.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private static boolean contains(JComboBox<String> urlField, String url) { for (int i = 0; i < urlField.getItemCount(); i++) { if (urlField.getItemAt(i).equals(url)) { return true; } } return false; }
Example 12
Source File: JComboBoxBinding.java From PyramidShader with GNU General Public License v3.0 | 5 votes |
public JComboBoxBinding(String property, JComboBox combo, int defaultValue) { if (property == null || combo == null) { throw new NullPointerException(); } if (property.equals("") || combo.getItemCount() == 0 || defaultValue < 0 || defaultValue >= combo.getItemCount()) { throw new IllegalArgumentException(); } _property = property; _combo = combo; _defaultValue = defaultValue; _validColor = combo.getBackground(); }
Example 13
Source File: PersistenceUnitPanel.java From netbeans with Apache License 2.0 | 5 votes |
/** * Sets the selected item in connection combo box. */ private void setSelectedConnection(){ DatabaseConnection connection = ProviderUtil.getConnection(persistenceUnit); if (connection != null){ jdbcComboBox.setSelectedItem(connection); } else { // custom connection (i.e. connection not registered in netbeans) Properties props = persistenceUnit.getProperties(); if (props != null){ Property[] properties = props.getProperty2(); String url = null; ArrayList<Provider> providers = new ArrayList<Provider>(); JComboBox activeCB = providerCombo.isVisible() ? providerCombo : libraryComboBox; for(int i=0; i<activeCB.getItemCount(); i++){ Object obj = activeCB.getItemAt(i); if(obj instanceof Provider){ providers.add((Provider) obj); } } Provider provider = ProviderUtil.getProvider(persistenceUnit, providers.toArray(new Provider[]{})); for (int i = 0; i < properties.length; i++) { String key = properties[i].getName(); if (provider.getJdbcUrl().equals(key)) { url = properties[i].getValue(); break; } } if (url == null) { url = NbBundle.getMessage(PersistenceUnitPanel.class, "LBL_CustomConnection");//NOI18N } jdbcComboBox.addItem(url); jdbcComboBox.setSelectedItem(url); } } }
Example 14
Source File: ConnectionFailedTask.java From JPPF with Apache License 2.0 | 5 votes |
/** * Perform the task. */ @Override public void run() { synchronized(statsHandler) { if (statsHandler.dataHolderMap.get(driver.getUuid()) != null) { final ConnectionDataHolder cdh = statsHandler.dataHolderMap.remove(driver.getUuid()); if (cdh != null) cdh.close(); } } JComboBox<?> box = null; while (statsHandler.getClientHandler().getServerListOption() == null) goToSleep(50L); final JPPFClientConnection c = driver.getConnection(); synchronized(statsHandler) { if (debugEnabled) log.debug("removing client connection " + c.getName() + " from driver combo box"); box = ((ComboBoxOption) statsHandler.getClientHandler().getServerListOption()).getComboBox(); final int count = box.getItemCount(); int idx = -1; for (int i=0; i<count; i++) { final Object o = box.getItemAt(i); if (c.equals(o)) { box.removeItemAt(i); idx = i; break; } } if ((idx >= 0) && (box.getItemCount() > 0)) { if ((statsHandler.getClientHandler().currentDriver == null) || c.equals(statsHandler.getClientHandler().currentDriver.getConnection())) { final int n = Math.min(idx, box.getItemCount()-1); final TopologyDriver item = (TopologyDriver) box.getItemAt(n); statsHandler.getClientHandler().currentDriver = item; box.setSelectedItem(item); } } } }
Example 15
Source File: FrmSectionPlot.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
private void updateEndDimSetS(JComboBox CB1, JComboBox CB2) { CB2.removeAllItems(); for (int i = 0; i < CB1.getItemCount(); i++) { CB2.addItem(CB1.getItemAt(i)); } CB2.setSelectedIndex(CB2.getItemCount() - 1); }
Example 16
Source File: FrmOneDim.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
private void updateEndDimSetS(JComboBox CB1, JComboBox CB2) { CB2.removeAllItems(); for (int i = 0; i < CB1.getItemCount(); i++) { CB2.addItem(CB1.getItemAt(i)); } CB2.setSelectedIndex(CB2.getItemCount() - 1); }
Example 17
Source File: BoundsPopupMenuListener.java From openAGV with Apache License 2.0 | 5 votes |
protected int getScrollBarWidth(BasicComboPopup popup, JScrollPane scrollPane) { // I can't find any property on the scrollBar to determine if it will be // displayed or not so use brute force to determine this. JComboBox<?> comboBox = (JComboBox) popup.getInvoker(); if (comboBox.getItemCount() > comboBox.getMaximumRowCount()) { return scrollPane.getVerticalScrollBar().getPreferredSize().width; } else { return 0; } }
Example 18
Source File: MainForm.java From zxpoly with GNU General Public License v3.0 | 4 votes |
private Optional<SourceSoundPort> showSelectSoundLineDialog( final List<SourceSoundPort> variants) { assertUiThread(); final JPanel panel = new JPanel(new FlowLayout(FlowLayout.TRAILING)); final String previouslySelectedDevice = AppOptions.getInstance().getLastSelectedAudioDevice(); final JComboBox<SourceSoundPort> comboBox = new JComboBox<>(variants.toArray(new SourceSoundPort[0])); comboBox.setPrototypeDisplayValue( new SourceSoundPort(null, "some very long device name to be shown", null)); comboBox.addActionListener(x -> { comboBox.setToolTipText(comboBox.getSelectedItem().toString()); }); comboBox.setToolTipText(comboBox.getSelectedItem().toString()); int index = -1; for (int i = 0; i < comboBox.getItemCount(); i++) { if (comboBox.getItemAt(i).toString().equals(previouslySelectedDevice)) { index = i; break; } } comboBox.setSelectedIndex(Math.max(0, index)); panel.add(new JLabel("Sound device:")); panel.add(comboBox); if (JOptionPane.showConfirmDialog( this, panel, "Select sound device", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE ) == JOptionPane.OK_OPTION) { final SourceSoundPort selected = (SourceSoundPort) comboBox.getSelectedItem(); AppOptions.getInstance().setLastSelectedAudioDevice(selected.toString()); return Optional.ofNullable(selected); } else { return Optional.empty(); } }
Example 19
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 20
Source File: Boot.java From MakeLobbiesGreatAgain with MIT License | 4 votes |
public static void getLocalAddr() throws InterruptedException, PcapNativeException, UnknownHostException, SocketException, ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException { if (Settings.getDouble("autoload", 0) == 1) { addr = InetAddress.getByName(Settings.get("addr", "")); return; } UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); final JFrame frame = new JFrame("Network Device"); frame.setFocusableWindowState(true); final JLabel ipLab = new JLabel("Select LAN IP obtained from Network Settings:", JLabel.LEFT); final JComboBox<String> lanIP = new JComboBox<String>(); final JLabel lanLabel = new JLabel("If your device IP isn't in the dropdown, provide it below."); final JTextField lanText = new JTextField(Settings.get("addr", "")); ArrayList<InetAddress> inets = new ArrayList<InetAddress>(); for (PcapNetworkInterface i : Pcaps.findAllDevs()) { for (PcapAddress x : i.getAddresses()) { InetAddress xAddr = x.getAddress(); if (xAddr != null && x.getNetmask() != null && !xAddr.toString().equals("/0.0.0.0")) { NetworkInterface inf = NetworkInterface.getByInetAddress(x.getAddress()); if (inf != null && inf.isUp() && !inf.isVirtual()) { inets.add(xAddr); lanIP.addItem((lanIP.getItemCount() + 1) + " - " + inf.getDisplayName() + " ::: " + xAddr.getHostAddress()); System.out.println("Found: " + lanIP.getItemCount() + " - " + inf.getDisplayName() + " ::: " + xAddr.getHostAddress()); } } } } if (lanIP.getItemCount() == 0) { JOptionPane.showMessageDialog(null, "Unable to locate devices.\nPlease try running the program in Admin Mode.\nIf this does not work, you may need to reboot your computer.", "Error", JOptionPane.ERROR_MESSAGE); System.exit(1); } lanIP.setFocusable(false); final JButton start = new JButton("Start"); start.addActionListener(e -> { try { if (lanText.getText().length() >= 7 && !lanText.getText().equals("0.0.0.0")) { // 7 is because the minimum field is 0.0.0.0 addr = InetAddress.getByName(lanText.getText()); System.out.println("Using IP from textfield: " + lanText.getText()); } else { addr = inets.get(lanIP.getSelectedIndex()); System.out.println("Using device from dropdown: " + lanIP.getSelectedItem()); } Settings.set("addr", addr.getHostAddress().replaceAll("/", "")); frame.setVisible(false); frame.dispose(); } catch (UnknownHostException e1) { e1.printStackTrace(); } }); frame.setLayout(new GridLayout(5, 1)); frame.add(ipLab); frame.add(lanIP); frame.add(lanLabel); frame.add(lanText); frame.add(start); frame.setAlwaysOnTop(true); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); while (frame.isVisible()) Thread.sleep(10); }