javax.swing.DefaultComboBoxModel#getSize ( )源码实例Demo

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

源代码1 项目: visualvm   文件: GcViewSupport.java
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());
            
        }
 
源代码2 项目: openjdk-8   文件: TreePosTest.java
/**
 * 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);
}
 
源代码3 项目: TencentKona-8   文件: CheckAttributedTree.java
/**
 * 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);
}
 
源代码4 项目: openjdk-8-source   文件: CheckAttributedTree.java
/**
 * 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);
}
 
源代码5 项目: hottub   文件: CheckAttributedTree.java
/**
 * 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);
}
 
源代码6 项目: nanoleaf-desktop   文件: ModernComboCheckBox.java
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;
}
 
源代码7 项目: openjdk-jdk8u   文件: TreePosTest.java
/**
 * 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);
}
 
源代码8 项目: openjdk-jdk8u   文件: CheckAttributedTree.java
/**
 * 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);
}
 
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);
}
 
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;
}
 
源代码11 项目: IrScrutinizer   文件: SerialPortSimpleBean.java
@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);
}
 
源代码12 项目: visualvm   文件: ExceptionsViewSupport.java
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());
    
}
 
源代码13 项目: netbeans   文件: AddFIActionPanel.java
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;
}
 
源代码14 项目: openjdk-jdk9   文件: TreePosTest.java
/**
 * 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);
}
 
源代码15 项目: netbeans   文件: DirectorySelectorCombo.java
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();
  }
}
 
源代码16 项目: netbeans   文件: DirectorySelectorCombo.java
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;
}
 
源代码17 项目: hottub   文件: TreePosTest.java
/**
 * 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);
}
 
源代码18 项目: openjdk-jdk9   文件: CheckAttributedTree.java
/**
 * 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);
}
 
源代码19 项目: netbeans   文件: ActionMappings.java
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);
            }
        }
    }
}
 
源代码20 项目: IrScrutinizer   文件: GirsClientBean.java
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);
        });
    }
}