Java Code Examples for javax.swing.DefaultComboBoxModel#getSize()

The following examples show how to use javax.swing.DefaultComboBoxModel#getSize() . 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: GcViewSupport.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private void handleAggregationChanged(boolean updateSecondary) {
            if (updateSecondary) {
                DefaultComboBoxModel model = (DefaultComboBoxModel)secondCombo.getModel();
                while (model.getSize() > 1) model.removeElementAt(1);
                
//                if (!Aggregation.CLASS.equals(firstCombo.getSelectedItem()) &&
//                    !Aggregation.CLASS_MESSAGE.equals(firstCombo.getSelectedItem()))
//                        model.addElement(Aggregation.CLASS);
//                
//                if (!Aggregation.MESSAGE.equals(firstCombo.getSelectedItem()) &&
//                    !Aggregation.CLASS_MESSAGE.equals(firstCombo.getSelectedItem()))
//                        model.addElement(Aggregation.MESSAGE);
//                
//                if (!Aggregation.CLASS.equals(firstCombo.getSelectedItem()) &&
//                    !Aggregation.MESSAGE.equals(firstCombo.getSelectedItem()) &&
//                    !Aggregation.CLASS_MESSAGE.equals(firstCombo.getSelectedItem()))
//                        model.addElement(Aggregation.CLASS_MESSAGE);
//                
//                if (!Aggregation.THREAD.equals(firstCombo.getSelectedItem()))
//                    model.addElement(Aggregation.THREAD);
            }
            
            updateButton.setEnabled(lastPrimary != firstCombo.getSelectedItem() ||
                                    lastPhase != secondChoice.isSelected());
            
        }
 
Example 2
Source File: SerialPortSimpleBean.java    From IrScrutinizer with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public SerialPortSimpleBean(GuiUtils guiUtils, String initialPort, int initialBaud, boolean settableBaudRate) {
    initComponents();
    this.guiUtils = guiUtils;
    listenable = false;
    DefaultComboBoxModel<String> model;
    try {
        List<String> portList = LocalSerialPort.getSerialPortNames(true); // Loads librxtxSerial (first time)
        model = new DefaultComboBoxModel<>(portList.toArray(new String[portList.size()]));
    } catch (IOException | LinkageError ex) {
        model =  new DefaultComboBoxModel<>(new String[]{ initialPort != null ? initialPort : notInitialized });
    }

    portComboBox.setModel(model);
    boolean hit = false;
    if (initialPort != null) {
        for (int i = 0; i < model.getSize(); i++) {
            if (initialPort.equalsIgnoreCase(model.getElementAt(i))) {
                hit = true;
                portComboBox.setSelectedIndex(i);
                break;
            }
        }
    }
    String actualPort = initialPort;
    if (!hit) {
        // Got a problem here, want to select a port that is not there, at least not now
        if (model.getSize() > 0) {
            portComboBox.setSelectedIndex(0);
            actualPort = portComboBox.getItemAt(0);
        }
    }
    setPortName(actualPort);
    setBaudRateUnconditionally(initialBaud);
    this.settableBaudRate = settableBaudRate;
    baudComboBox.setEnabled(settableBaudRate);
    baudRateLabel.setEnabled(settableBaudRate);
}
 
Example 3
Source File: CheckAttributedTree.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add another entry to the list of errors.
 * @param file The file containing the error
 * @param check The condition that was being tested, and which failed
 * @param encl the enclosing tree node
 * @param self the tree node containing the error
 */
void addEntry(JavaFileObject file, String check, Info encl, Info self) {
    Entry e = new Entry(file, check, encl, self);
    DefaultComboBoxModel m = (DefaultComboBoxModel) entries.getModel();
    m.addElement(e);
    if (m.getSize() == 1)
        entries.setSelectedItem(e);
}
 
Example 4
Source File: TreePosTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add another entry to the list of errors.
 * @param file The file containing the error
 * @param check The condition that was being tested, and which failed
 * @param encl the enclosing tree node
 * @param self the tree node containing the error
 */
void addEntry(JavaFileObject file, String check, Info encl, Info self) {
    Entry e = new Entry(file, check, encl, self);
    DefaultComboBoxModel m = (DefaultComboBoxModel) entries.getModel();
    m.addElement(e);
    if (m.getSize() == 1)
        entries.setSelectedItem(e);
}
 
Example 5
Source File: DirectorySelectorCombo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ComboListElement addPath(String path) {
  DefaultComboBoxModel model = (DefaultComboBoxModel)fileMRU.getModel();
  ComboListElement newPath = new StringComboListElement(path);
  int index = model.getIndexOf(newPath);
  if (index == -1) {
    model.insertElementAt(newPath, 1);
  }
  if (model.getSize() > itemCountLimit + 3) {
    model.removeElementAt(model.getSize() - 3);
  }
  return newPath;
}
 
Example 6
Source File: DirectorySelectorCombo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void fileMRUPopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_fileMRUPopupMenuWillBecomeVisible
  DefaultComboBoxModel model = (DefaultComboBoxModel)fileMRU.getModel();
  Collection mukls = new ArrayList();
  for(int i=0;i<model.getSize();i++) {
    if (!(model.getElementAt(i) instanceof ComboListElement))
      continue;
    if (((ComboListElement)model.getElementAt(i)).isVolatile())
      mukls.add(model.getElementAt(i));
  }
  for (Iterator it = mukls.iterator(); it.hasNext();) {
    Object elem = (Object) it.next();
    model.removeElement(elem);
    it.remove();
  }
}
 
Example 7
Source File: TreePosTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add another entry to the list of errors.
 * @param file The file containing the error
 * @param check The condition that was being tested, and which failed
 * @param encl the enclosing tree node
 * @param self the tree node containing the error
 */
void addEntry(JavaFileObject file, String check, Info encl, Info self) {
    Entry e = new Entry(file, check, encl, self);
    DefaultComboBoxModel m = (DefaultComboBoxModel) entries.getModel();
    m.addElement(e);
    if (m.getSize() == 1)
        entries.setSelectedItem(e);
}
 
Example 8
Source File: AddFIActionPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean containsActionPath(String path) {
    DefaultComboBoxModel model = (DefaultComboBoxModel)cbAction.getModel();
    for (int i=0; i<model.getSize(); i++) {
        if (path.equals(model.getElementAt(i))) return true;
    }
    return false;
}
 
Example 9
Source File: ExceptionsViewSupport.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void handleAggregationChanged(boolean updateSecondary) {
    if (updateSecondary) {
        DefaultComboBoxModel model = (DefaultComboBoxModel)secondCombo.getModel();
        while (model.getSize() > 1) model.removeElementAt(1);
        
        if (!Aggregation.CLASS.equals(firstCombo.getSelectedItem()) &&
            !Aggregation.CLASS_MESSAGE.equals(firstCombo.getSelectedItem()))
                model.addElement(Aggregation.CLASS);
        
        if (!Aggregation.MESSAGE.equals(firstCombo.getSelectedItem()) &&
            !Aggregation.CLASS_MESSAGE.equals(firstCombo.getSelectedItem()))
                model.addElement(Aggregation.MESSAGE);
        
        if (!Aggregation.CLASS.equals(firstCombo.getSelectedItem()) &&
            !Aggregation.MESSAGE.equals(firstCombo.getSelectedItem()) &&
            !Aggregation.CLASS_MESSAGE.equals(firstCombo.getSelectedItem()))
                model.addElement(Aggregation.CLASS_MESSAGE);
        
        if (!Aggregation.THREAD.equals(firstCombo.getSelectedItem()))
            model.addElement(Aggregation.THREAD);
    }
    
    updateButton.setEnabled(lastMode != modeCombo.getSelectedIndex() ||
                            lastPrimary != firstCombo.getSelectedItem() ||
                            lastSecondary != secondCombo.getSelectedItem());
    
}
 
Example 10
Source File: TreePosTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add another entry to the list of errors.
 * @param file The file containing the error
 * @param check The condition that was being tested, and which failed
 * @param encl the enclosing tree node
 * @param self the tree node containing the error
 */
void addEntry(JavaFileObject file, String check, Info encl, Info self) {
    Entry e = new Entry(file, check, encl, self);
    DefaultComboBoxModel m = (DefaultComboBoxModel) entries.getModel();
    m.addElement(e);
    if (m.getSize() == 1)
        entries.setSelectedItem(e);
}
 
Example 11
Source File: AutoSuggest.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private ComboBoxModel<String> getSuggestedModel() {
    DefaultComboBoxModel<String> m = new DefaultComboBoxModel<>();
    for (String s : searchList) {
        if (s.toLowerCase().contains(getSearchString().toLowerCase())) {
            m.addElement(s);
        }
    }
    if (m.getSize() == 0) {
        m = new DefaultComboBoxModel<>(searchList.toArray(new String[searchList.size()]));
    }
    return m;
}
 
Example 12
Source File: PersistenceProviderComboboxHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void initCombo(JComboBox providerCombo) {
    
    DefaultComboBoxModel providers = new DefaultComboBoxModel();
    
    for(Provider each : providerSupplier.getSupportedProviders()){
       providers.addElement(each);
    }

    if (providers.getSize() == 0 && providerSupplier.supportsDefaultProvider()){
        providers.addElement(ProviderUtil.DEFAULT_PROVIDER);
    } 

    if (providers.getSize() == 0){
        providers.addElement(EMPTY);
    }
    
    providerCombo.setModel(providers);
    providerCombo.addItem(SEPARATOR);
    providerCombo.addItem(new NewPersistenceLibraryItem());
    providerCombo.addItem(new ManageLibrariesItem());
    providerCombo.setRenderer(new PersistenceProviderCellRenderer(getDefaultProvider(providers)));
    //select either default or first or preferred provider depending on project details
    int selectIndex = 0;
    if(providers.getSize()>1 && providers.getElementAt(0) instanceof Provider){
        String defProviderVersion = ProviderUtil.getVersion((Provider) providers.getElementAt(0));
        boolean specialCase = (Util.isJPAVersionSupported(project, Persistence.VERSION_2_0) || Util.isJPAVersionSupported(project, Persistence.VERSION_2_1)) && (defProviderVersion == null || defProviderVersion.equals(Persistence.VERSION_1_0));//jpa 2.0 is supported by default (or first) is jpa1.0 or udefined version provider
        if(specialCase){
            for (int i = 1; i<providers.getSize() ; i++){
                if(preferredProvider.equals(providers.getElementAt(i))){
                    selectIndex = i;
                    break;
                }
            }
        }
    }
    providerCombo.setSelectedIndex(selectIndex);
}
 
Example 13
Source File: CheckAttributedTree.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add another entry to the list of errors.
 * @param file The file containing the error
 * @param check The condition that was being tested, and which failed
 * @param encl the enclosing tree node
 * @param self the tree node containing the error
 */
void addEntry(JavaFileObject file, String check, Info encl, Info self) {
    Entry e = new Entry(file, check, encl, self);
    DefaultComboBoxModel m = (DefaultComboBoxModel) entries.getModel();
    m.addElement(e);
    if (m.getSize() == 1)
        entries.setSelectedItem(e);
}
 
Example 14
Source File: TreePosTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add another entry to the list of errors.
 * @param file The file containing the error
 * @param check The condition that was being tested, and which failed
 * @param encl the enclosing tree node
 * @param self the tree node containing the error
 */
void addEntry(JavaFileObject file, String check, Info encl, Info self) {
    Entry e = new Entry(file, check, encl, self);
    DefaultComboBoxModel m = (DefaultComboBoxModel) entries.getModel();
    m.addElement(e);
    if (m.getSize() == 1)
        entries.setSelectedItem(e);
}
 
Example 15
Source File: ModernComboCheckBox.java    From nanoleaf-desktop with MIT License 5 votes vote down vote up
private String[] modelToArray(DefaultComboBoxModel<T> model)
{
	String[] items = new String[model.getSize()];
	for (int i = 0; i < model.getSize(); i++)
	{
		items[i] = (String)model.getElementAt(i);
	}
	return items;
}
 
Example 16
Source File: CheckAttributedTree.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add another entry to the list of errors.
 * @param file The file containing the error
 * @param check The condition that was being tested, and which failed
 * @param encl the enclosing tree node
 * @param self the tree node containing the error
 */
void addEntry(JavaFileObject file, String check, Info encl, Info self) {
    Entry e = new Entry(file, check, encl, self);
    DefaultComboBoxModel m = (DefaultComboBoxModel) entries.getModel();
    m.addElement(e);
    if (m.getSize() == 1)
        entries.setSelectedItem(e);
}
 
Example 17
Source File: CheckAttributedTree.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add another entry to the list of errors.
 * @param file The file containing the error
 * @param check The condition that was being tested, and which failed
 * @param encl the enclosing tree node
 * @param self the tree node containing the error
 */
void addEntry(JavaFileObject file, String check, Info encl, Info self) {
    Entry e = new Entry(file, check, encl, self);
    DefaultComboBoxModel m = (DefaultComboBoxModel) entries.getModel();
    m.addElement(e);
    if (m.getSize() == 1)
        entries.setSelectedItem(e);
}
 
Example 18
Source File: CheckAttributedTree.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add another entry to the list of errors.
 * @param file The file containing the error
 * @param check The condition that was being tested, and which failed
 * @param encl the enclosing tree node
 * @param self the tree node containing the error
 */
void addEntry(JavaFileObject file, String check, Info encl, Info self) {
    Entry e = new Entry(file, check, encl, self);
    DefaultComboBoxModel m = (DefaultComboBoxModel) entries.getModel();
    m.addElement(e);
    if (m.getSize() == 1)
        entries.setSelectedItem(e);
}
 
Example 19
Source File: ActionMappings.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    Object obj = lstMappings.getSelectedValue(); 
    if (obj != null) {
        MappingWrapper wr = (MappingWrapper)obj;
        if (wr.getToolbarIconPath() != null) {
            wr.setToolbarPath(null);
            updateToolbarButton(wr);
        } else {
            //add
            JPanel pnl = new JPanel();
            pnl.setLayout(new FlowLayout(FlowLayout.LEADING));
            pnl.add(new JLabel(LBL_SetIcon()));
            List<String> allIcons = RunCustomMavenAction.createAllActionIcons();
            for (int i = 0; i < lstMappings.getModel().getSize(); i++) {
                MappingWrapper wr0 = (MappingWrapper) lstMappings.getModel().getElementAt(i);
                if (wr0.getToolbarIconPath() != null) {
                    allIcons.remove(wr0.getToolbarIconPath());
                }
            }

            DefaultComboBoxModel<String> cbModel = new DefaultComboBoxModel<String>(allIcons.toArray(new String[0]));
            boolean hasAvailable;
            if (cbModel.getSize() != 0) {
                hasAvailable = true;
                JComboBox<String> cb = new JComboBox<String>();
                cb.setModel(cbModel);
                pnl.add(cb);
                cb.setRenderer(new DefaultListCellRenderer() {

                    @Override
                    public Component getListCellRendererComponent(JList arg0, Object arg1, int arg2, boolean arg3, boolean arg4) {
                        Component sup = super.getListCellRendererComponent(arg0, arg1, arg2, arg3, arg4);
                        if (sup instanceof JLabel && arg1 != null) {
                            JLabel lbl = (JLabel) sup;
                            lbl.setIcon(ImageUtilities.loadImageIcon((String) arg1, false));
                            lbl.setText("");
                        }
                        return sup;
                    }
                });
            } else {
                hasAvailable = false;
                pnl.add(new JLabel(LBL_No_More_Icons()));
            }
            DialogDescriptor dd = new DialogDescriptor(pnl, TIT_SetIcon());
            if (!hasAvailable) {
                dd.setOptions(new Object[] {BTN_Close()});
                dd.setClosingOptions(dd.getOptions());
            }
            Object ret = DialogDisplayer.getDefault().notify(dd);
            if (ret == DialogDescriptor.OK_OPTION) {
                wr.setToolbarPath((String) cbModel.getSelectedItem());
                updateToolbarButton(wr);
            }
        }
    }
}
 
Example 20
Source File: GirsClientBean.java    From IrScrutinizer with GNU General Public License v3.0 4 votes vote down vote up
public GirsClientBean(GuiUtils guiUtils, Props properties) {
    this.guiUtils = guiUtils;
    this.properties = properties;
    this.pingTimeout = defaultPingTimeout;
    initComponents();
    String initialPort = properties != null ? properties.getGirsClientSerialPortName() : defaultPortName;
    DefaultComboBoxModel<String> model;
    try {
        List<String> portList = LocalSerialPort.getSerialPortNames(true);
        model = new DefaultComboBoxModel<>(portList.toArray(new String[portList.size()]));
    } catch (IOException | LinkageError ex) {
        model =  new DefaultComboBoxModel<>(new String[]{ initialPort != null ? initialPort : notInitialized });
    }

    portComboBox.setModel(model);
    boolean hit = false;
    if (initialPort != null) {
        for (int i = 0; i < model.getSize(); i++) {
            if (initialPort.equalsIgnoreCase(model.getElementAt(i))) {
                hit = true;
                portComboBox.setSelectedIndex(i);
                break;
            }
        }
    }
    String actualPort = initialPort;
    if (!hit) {
        // Got a problem here, want to select a port that is not there, at least not now
        if (model.getSize() > 0) {
            portComboBox.setSelectedIndex(0);
            actualPort = portComboBox.getItemAt(0);
        }
    }
    setPortName(actualPort);
    setBaudRate(properties != null ? properties.getGirsClientSerialPortBaudRate() : defaultBaudRate);
    setIpName(properties != null ? properties.getGirsClientIPName() : defaultHost);
    setPortNumber(properties != null ? properties.getGirsClientPortNumber() : defaultPortNumber);
    setType(properties != null ? Type.valueOf(properties.getGirsClientType()) : defaultType);

    if (properties != null) { // to be javabeans safe...
        properties.addVerboseChangeListener((String name1, Object oldValue, Object newValue) -> {
            if (hardware != null)
                hardware.setVerbose((Boolean) newValue);
        });
    }
}