Java Code Examples for javax.swing.JComboBox#insertItemAt()
The following examples show how to use
javax.swing.JComboBox#insertItemAt() .
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: InfoPanel.java From the-one with GNU General Public License v3.0 | 6 votes |
/** * 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(); }
Example 2
Source File: DesignerTablePanel.java From nextreports-designer with Apache License 2.0 | 6 votes |
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); } } } } }
Example 3
Source File: DesignerTablePanel.java From nextreports-designer with Apache License 2.0 | 6 votes |
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(""); } }
Example 4
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 5
Source File: AddThemeEntry.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
/** * 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; } }); } }