javax.swing.JComboBox#insertItemAt ( )源码实例Demo

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

源代码1 项目: the-one   文件: InfoPanel.java
/**
 * Show information about a host
 * @param host Host to show the information of
 */
public void showInfo(DTNHost host) {
	Vector<Message> messages = new Vector<Message>(host.getMessageCollection());
	Collections.sort(messages);
	reset();
	this.selectedHost = host;
	String text = (host.isMovementActive() ? "" : "INACTIVE ") + host +
		" at " + host.getLocation();

	msgChooser = new JComboBox(messages);
	msgChooser.insertItemAt(messages.size() + " messages", 0);
	msgChooser.setSelectedIndex(0);
	msgChooser.addActionListener(this);

	routingInfoButton = new JButton("routing info");
	routingInfoButton.addActionListener(this);

	this.add(new JLabel(text));
	this.add(msgChooser);
	this.add(routingInfoButton);
	this.revalidate();
}
 
源代码2 项目: nextreports-designer   文件: DesignerTablePanel.java
private void updateGroupByColumn(JComboBox groupByCombo, boolean output) {
    if (output) {
    	if (hasAggregateFunction()) {
    		groupByCombo.removeItem("");
    	}
    }
    int rowCount = model.getRowCount();
    for (int i = 0; i < rowCount; i++) {
        MyRow row = (MyRow) model.getObjectForRow(i);
        if (row.output && "".equals(row.groupBy)) {
            row.groupBy = GROUP_BY;
            model.fireTableCellUpdated(i, 6);
            selectQuery.addGroupByColumn(row.column);
        }
        if (output && row.output) {                    
            JComboBox groupByCombo2 = (JComboBox) ((DefaultCellEditor) table.getCellEditor(i, 6)).getComponent();
            if (hasAggregateFunction()) {
            	groupByCombo2.removeItem("");
            } else {
            	if (!hasEmpty(groupByCombo2.getModel())) {
            		groupByCombo2.insertItemAt("", 0);
            	}
            }
        }
    }
}
 
源代码3 项目: nextreports-designer   文件: DesignerTablePanel.java
public void updateGroupByItems(int dragRow, int dropRow) {
    MyRow drag_row = (MyRow) model.getObjectForRow(dragRow);
    JComboBox groupByComboDrag = (JComboBox) ((DefaultCellEditor) table.getCellEditor(dragRow, 6)).getComponent();

    MyRow drop_row = (MyRow) model.getObjectForRow(dropRow);
    JComboBox groupByComboDrop = (JComboBox) ((DefaultCellEditor) table.getCellEditor(dropRow, 6)).getComponent();

    String sDrag = (String) groupByComboDrag.getItemAt(0);
    String sDrop = (String) groupByComboDrop.getItemAt(0);

    if ("".equals(sDrag) && !sDrag.equals(sDrop)) {
        groupByComboDrop.insertItemAt("", 0);
        groupByComboDrag.removeItem("");
    }

    if ("".equals(sDrop) && !sDrop.equals(sDrag)) {
        groupByComboDrag.insertItemAt("", 0);
        groupByComboDrop.removeItem("");
    }
}
 
源代码4 项目: netbeans   文件: UI.java
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);
    }
}
 
源代码5 项目: CodenameOne   文件: AddThemeEntry.java
/**
 * Initializes a combo box for editing UIID's
 */
public static void initUIIDComboBox(JComboBox jc) {
    jc.setEditable(true);
    Vector uiids = new Vector();
    uiids.add("");
    for(Object k : Accessor.getThemeProps().keySet()) {
        String key = (String)k;
        int dot = key.indexOf('.');
        if(dot > -1 && key.indexOf('@') < 0) {
            key = key.substring(0, dot);
            if(!uiids.contains(key)) {
                uiids.add(key);
            }
        }
    }
    Collections.sort(uiids, String.CASE_INSENSITIVE_ORDER);
    jc.setModel(new DefaultComboBoxModel(uiids));
    com.codename1.ui.Form currentForm = com.codename1.ui.Display.getInstance().getCurrent();
    if(currentForm != null) {
        final List<String> currentFormUIIDs = new ArrayList<String>();
        findAllUIIDs(currentFormUIIDs, currentForm);
        Collections.sort(currentFormUIIDs, String.CASE_INSENSITIVE_ORDER);
        Collections.reverse(currentFormUIIDs);
        for(String cmp : currentFormUIIDs) {
            jc.insertItemAt(cmp, 1);
        }
        jc.setRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                String uiid = (String)value;
                if(index > 0 && index < currentFormUIIDs.size() + 1) {
                    value = "<html><body><b>" + value + "</b></body></html>";
                } else {
                    if(value == null || ((String)value).length() == 0) {
                        value = "[null]";
                    }
                }
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                setIcon(ThemeEditor.getUIIDPreviewImage(uiid, false, false, false));
                return this;
            }
        });
    }
}