List of usage examples for javax.swing JComboBox getEditor
public ComboBoxEditor getEditor()
JComboBox
field. From source file:edu.ku.brc.specify.utilapps.sp5utils.Sp5Forms.java
/** * @param fi//from ww w .jav a 2 s . c o m * @return */ protected FormPanelInfo createPanel(final FormInfo formInfo) { CellConstraints cc = new CellConstraints(); JPanel panel = new JPanel(null); int maxWidth = 0; int maxHeight = 0; int maxCellWidth = 0; int maxCellHeight = 0; for (FormFieldInfo fi : formInfo.getFields()) { System.out.println(fi.getCaption()); boolean addLbl = true; JComponent comp = null; switch (fi.getControlTypeNum()) { case 4: comp = createComboBox(); // 'Picklist' break; case 5: { JComboBox cbx = createComboBox(); //new ValComboBoxFromQuery(DBTableIdMgr.getInstance().getInfoById(1), "catalogNumber","CatalogNumber","CatalogNumber"," "," "," "," "," ",ValComboBoxFromQuery.CREATE_ALL);// 'QueryCombo' cbx.setEditable(true); cbx.getEditor().setItem(fi.getCaption()); JPanel cPanel = new JPanel(new BorderLayout()); cPanel.add(cbx, BorderLayout.CENTER); cPanel.add(createElipseBtn(), BorderLayout.EAST); comp = cPanel; addLbl = false; break; } case 7: { String uniqueKey = getUniqueKey(fi.getRelatedTableName(), "Embedded", fi.getParent().getFormType()); FormInfo subForm = formHash.get(uniqueKey); if (subForm == null) { uniqueKey = getUniqueKey(fi.getRelatedTableName(), "Embedded", null); subForm = formHash.get(uniqueKey); } if (subForm != null) { Vector<String> headers = new Vector<String>(); for (int i = 0; i < subForm.getFields().size(); i++) { headers.add(subForm.getFields().get(i).getCaption()); } JPanel p = new JPanel(new BorderLayout()); p.add(UIHelper.createScrollPane(new JTable(new Vector<Vector<Object>>(), headers)), BorderLayout.CENTER); // 'Grid' comp = p; addLbl = false; } break; } case 8: // 'EmbeddedForm' { String uniqueKey = getUniqueKey(fi.getRelatedTableName(), "Embedded", fi.getParent().getFormType()); FormInfo subForm = formHash.get(uniqueKey); if (subForm == null) { uniqueKey = getUniqueKey(fi.getRelatedTableName(), "Embedded", null); subForm = formHash.get(uniqueKey); } comp = (subForm != null ? createPanel(subForm).getPanel() : new JPanel()); addLbl = fi.getControlTypeNum() != 8; break; } case 9: { comp = createElipseBtn(); break; } case 20: comp = createScrollPane(createTextArea()); // 'Memo' break; case 21: comp = null;//createComboBox(); // 'MenuItem' break; case 46: comp = createTextField("URL"); // 'URL' break; default: if (fi.getDataTypeNum() == 4) { comp = createCheckBox(" "); } else { comp = createTextField(); } } // switch if (comp != null) { String toolTip = "Field: " + fi.getSp5FieldName() + (StringUtils.isNotEmpty(fi.getSp6FieldName()) && fi.getSp6FieldName().equalsIgnoreCase(fi.getSp5FieldName()) ? " Sp6: " + fi.getSp6FieldName() : ""); comp.setToolTipText(toolTip); PanelBuilder pb = new PanelBuilder(new FormLayout("p,1px,f:p:g", "f:p:g,p,f:p:g")); pb.getPanel().setToolTipText(toolTip); pb.getPanel().setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY)); if (addLbl) { pb.add(createLabel(fi.getCaption()), cc.xy(1, 2)); } pb.add(comp, cc.xy(3, 2)); panel.add(pb.getPanel()); maxWidth = Math.max(maxWidth, fi.getLeft() + fi.getWidth()); maxHeight = Math.max(maxHeight, fi.getTop() + fi.getHeight()); maxCellWidth = Math.max(maxWidth, fi.getCellX() + fi.getCellWidth()); maxCellHeight = Math.max(maxHeight, fi.getCellY() + fi.getCellHeight()); boolean newWay = false; if (newWay) { Rectangle r = fi.getBoundsFromCellDim(); pb.getPanel().setLocation(r.x, r.y); pb.getPanel().setSize(r.width, r.height); } else { pb.getPanel().setLocation(fi.getLeft(), fi.getTop()); pb.getPanel().setSize(fi.getWidth(), fi.getHeight()); } System.out.println("MaxW: " + maxWidth + " " + maxCellWidth); System.out.println("MaxH: " + maxHeight + " " + maxCellHeight); } } boolean newWay = false; if (newWay) { int cw = FormFieldInfo.getSegWidth(); panel.setPreferredSize(new Dimension(maxCellWidth * cw, maxCellHeight * cw)); panel.setSize(new Dimension(maxCellWidth * cw, maxCellHeight * cw)); } else { panel.setPreferredSize(new Dimension(maxWidth, maxHeight)); panel.setSize(new Dimension(maxWidth, maxHeight)); } System.out.println("MaxW: " + maxWidth + " " + maxCellWidth); System.out.println("MaxH: " + maxHeight + " " + maxCellHeight); return new FormPanelInfo(formInfo.getTitle(), panel, maxWidth, maxHeight); }
From source file:com.alvermont.terraj.planet.ui.MainFrame.java
/** * Set a combo box to have a numeric editor with validation * * @param box The <code>JComboBox</code> to be set up *///from www. j a v a 2 s .c o m protected void setComboNumericEditor(JComboBox<? extends String> box) { final ComboBoxEditor editor = box.getEditor(); final Component editorComponent = editor.getEditorComponent(); if (editorComponent instanceof JTextField) { final JTextField textField = (JTextField) editorComponent; textField.setDocument(new CustomDocument()); } }
From source file:org.apache.cayenne.modeler.editor.ObjEntityRelationshipPanel.java
protected void rebuildTable(ObjEntity entity) { final ObjRelationshipTableModel model = new ObjRelationshipTableModel(entity, mediator, this); model.addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent e) { if (table.getSelectedRow() >= 0) { ObjRelationship rel = model.getRelationship(table.getSelectedRow()); enabledResolve = rel.getSourceEntity().getDbEntity() != null; resolveMenu.setEnabled(enabledResolve); }//from w w w . java 2s . c o m } }); table.setModel(model); table.setRowHeight(25); table.setRowMargin(3); TableColumn col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_TARGET_PATH); col.setCellEditor(new DbRelationshipPathComboBoxEditor()); col.setCellRenderer(new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); setToolTipText( "To choose relationship press enter two times.To choose next relationship press dot."); return this; } }); col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_DELETE_RULE); JComboBox deleteRulesCombo = Application.getWidgetFactory().createComboBox(DELETE_RULES, false); deleteRulesCombo.setFocusable(false); deleteRulesCombo.setEditable(true); ((JComponent) deleteRulesCombo.getEditor().getEditorComponent()).setBorder(null); deleteRulesCombo.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); deleteRulesCombo.setSelectedIndex(0); // Default to the first value col.setCellEditor(Application.getWidgetFactory().createCellEditor(deleteRulesCombo)); tablePreferences.bind(table, null, null, null, ObjRelationshipTableModel.REL_NAME, true); }
From source file:org.eclipse.jubula.rc.swing.listener.RecordActions.java
/** * creates CAP for Actions Replace Text//from w w w . ja va 2 s . c om * @param source Component */ protected void replaceText(Component source) { Component src = source; Component parent = getComponentParent() != null ? getComponentParent() : src.getParent(); if (parent instanceof JComboBox) { src = parent; } String text = null; boolean isEditable = false; boolean isCbxItem = false; boolean isSupported = true; if (src instanceof JTextComponent) { JTextComponent jtf = (JTextComponent) src; text = jtf.getText(); isEditable = jtf.isEditable(); if ((source instanceof JTextArea || source instanceof JTextPane || source instanceof JEditorPane) && (text.indexOf(CharacterConstants.LINEFEED) != -1 || text.indexOf(CharacterConstants.RETURN) != -1)) { isSupported = false; sendInfoMessage(Constants.REC_MULTILINE_MSG); } if (parent instanceof JTable) { JTable tbl = (JTable) parent; replaceTableText(src, tbl, text); return; } } if (src instanceof JComboBox) { JComboBox cbx = (JComboBox) src; isEditable = cbx.isEditable(); if (isEditable) { ComboBoxEditor cbxEditor = cbx.getEditor(); text = cbxEditor.getItem().toString(); String[] cbxItems = m_recordHelper.getRenderedComboItems(cbx); for (int i = 0; i < cbxItems.length; i++) { String item = cbxItems[i]; if (item.equals(text)) { isCbxItem = true; } } } else { return; } } if (text.length() > Constants.REC_MAX_STRING_LENGTH) { ShowObservInfoMessage infoMsg = new ShowObservInfoMessage(Constants.REC_MAX_STRING_MSG); try { AUTServer.getInstance().getServerCommunicator().send(infoMsg); } catch (CommunicationException e) { // no log available here } return; } if (m_map.get(source) != null && !(text.equals(m_map.get(source).toString())) && isSupported && isEditable && !isCbxItem) { m_map.put(src, text); IComponentIdentifier id = null; try { id = ComponentHandler.getIdentifier(src); Action a = new Action(); a = m_recordHelper.compSysToAction(id, "CompSystem.InputText"); //$NON-NLS-1$ List parameterValues = new LinkedList(); text = StringParsing.singleQuoteText(text); parameterValues.add(text); String logName = createLogicalName(src, id); createCAP(a, id, parameterValues, logName); } catch (NoIdentifierForComponentException nifce) { // no identifier for the component, log this as an error log.error("no identifier for '" + src); //$NON-NLS-1$ } } }
From source file:org.eclipse.jubula.rc.swing.tester.adapter.JComboBoxAdapter.java
/** * @param component/*from w ww.ja v a2s .c o m*/ * the combobox * @return the editor used to render and edit the selected item in the * JComboBox field. * @throws StepExecutionException * if the editor comonent could not be found */ private Component getComboBoxEditorComponent(JComboBox component) throws StepExecutionException { ComboBoxEditor cbe = component.getEditor(); if (cbe == null) { throw new StepExecutionException("no ComboBoxEditor found", //$NON-NLS-1$ EventFactory.createActionError(TestErrorEvent.COMP_NOT_FOUND)); } Component c = cbe.getEditorComponent(); if (c == null) { throw new StepExecutionException("no EditorComponent found", //$NON-NLS-1$ EventFactory.createActionError(TestErrorEvent.COMP_NOT_FOUND)); } return c; }
From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java
private boolean hasFocus() { // if the component has focus, other code far, far away sets the nice yellow // background which we don't want to overwride here ... JComponent focusComponent = getControlComponent(); if (getJComponent() instanceof LabeledComboBox) { JComboBox cb = ((LabeledComboBox) getJComponent()).getJComboBox(); focusComponent = (JComponent) (cb.getEditor() != null ? cb.getEditor().getEditorComponent() : cb); }/*from www . j ava2s . c o m*/ return focusComponent.hasFocus(); }
From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java
private TableCellRenderer getCellRenderer(final SwingTreeCol col) { return new DefaultTableCellRenderer() { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { ColumnType colType = col.getColumnType(); if (colType == ColumnType.DYNAMIC) { colType = ColumnType.valueOf(extractDynamicColType(elements.toArray()[row], column)); }/*from w w w. j a va 2 s. c o m*/ final XulTreeCell cell = getRootChildren().getItem(row).getRow().getCell(column); switch (colType) { case CHECKBOX: JCheckBox checkbox = new JCheckBox(); if (value instanceof String) { checkbox.setSelected(((String) value).equalsIgnoreCase("true")); //$NON-NLS-1$ } else if (value instanceof Boolean) { checkbox.setSelected((Boolean) value); } else if (value == null) { checkbox.setSelected(false); } if (isSelected) { checkbox.setBackground(Color.LIGHT_GRAY); } checkbox.setEnabled(!cell.isDisabled()); return checkbox; case COMBOBOX: case EDITABLECOMBOBOX: Vector data; final JComboBox comboBox = new JComboBox(); if (cell == null) { } else { data = (cell.getValue() != null) ? (Vector) cell.getValue() : new Vector(); if (data == null) { logger.debug("SwingTreeCell combobox data is null, passed in value: " + value); //$NON-NLS-1$ if (value instanceof Vector) { data = (Vector) value; } } if (data != null) { comboBox.setModel(new DefaultComboBoxModel(data)); try { comboBox.setSelectedIndex(cell.getSelectedIndex()); } catch (Exception e) { logger.error("error setting selected index on the combobox editor"); //$NON-NLS-1$ } } } if (colType == ColumnType.EDITABLECOMBOBOX) { comboBox.setEditable(true); ((JTextComponent) comboBox.getEditor().getEditorComponent()).setText(cell.getLabel()); } if (isSelected) { comboBox.setBackground(Color.LIGHT_GRAY); } comboBox.setEnabled(!cell.isDisabled()); return comboBox; case CUSTOM: return new CustomCellEditorWrapper(cell, customEditors.get(col.getType())); default: JLabel label = new JLabel((String) value); if (isSelected) { label.setOpaque(true); label.setBackground(Color.LIGHT_GRAY); } return label; } } }; }
From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java
private TableCellEditor getCellEditor(final SwingTreeCol col) { return new DefaultCellEditor(new JComboBox()) { JComponent control;/*from w ww. j a va 2 s . c o m*/ @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, final int row, final int column) { Component comp; ColumnType colType = col.getColumnType(); if (colType == ColumnType.DYNAMIC) { colType = ColumnType.valueOf(extractDynamicColType(elements.toArray()[row], column)); } final XulTreeCell cell = getRootChildren().getItem(row).getRow().getCell(column); switch (colType) { case CHECKBOX: final JCheckBox checkbox = new JCheckBox(); final JTable tbl = table; checkbox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { SwingTree.this.table.setValueAt(checkbox.isSelected(), row, column); tbl.getCellEditor().stopCellEditing(); } }); control = checkbox; if (value instanceof String) { checkbox.setSelected(((String) value).equalsIgnoreCase("true")); //$NON-NLS-1$ } else if (value instanceof Boolean) { checkbox.setSelected((Boolean) value); } else if (value == null) { checkbox.setSelected(false); } if (isSelected) { checkbox.setBackground(Color.LIGHT_GRAY); } comp = checkbox; checkbox.setEnabled(!cell.isDisabled()); break; case EDITABLECOMBOBOX: case COMBOBOX: Vector val = (value != null && value instanceof Vector) ? (Vector) value : new Vector(); final JComboBox comboBox = new JComboBox(val); if (isSelected) { comboBox.setBackground(Color.LIGHT_GRAY); } if (colType == ColumnType.EDITABLECOMBOBOX) { comboBox.setEditable(true); final JTextComponent textComp = (JTextComponent) comboBox.getEditor().getEditorComponent(); textComp.addKeyListener(new KeyListener() { private String oldValue = ""; //$NON-NLS-1$ public void keyPressed(KeyEvent e) { oldValue = textComp.getText(); } public void keyReleased(KeyEvent e) { if (oldValue != null && !oldValue.equals(textComp.getText())) { SwingTree.this.table.setValueAt(textComp.getText(), row, column); oldValue = textComp.getText(); } else if (oldValue == null) { // AWT error where sometimes the keyReleased is fired before keyPressed. oldValue = textComp.getText(); } else { logger.debug("Special key pressed, ignoring"); //$NON-NLS-1$ } } public void keyTyped(KeyEvent e) { } }); comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { // if(textComp.hasFocus() == false && comboBox.hasFocus()){ SwingTree.logger.debug("Setting ComboBox value from editor: " //$NON-NLS-1$ + comboBox.getSelectedItem() + ", " + row + ", " + column); //$NON-NLS-1$ //$NON-NLS-2$ SwingTree.this.table.setValueAt(comboBox.getSelectedIndex(), row, column); // } } }); } else { comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { SwingTree.logger.debug("Setting ComboBox value from editor: " //$NON-NLS-1$ + comboBox.getSelectedItem() + ", " + row + ", " + column); //$NON-NLS-1$ //$NON-NLS-2$ SwingTree.this.table.setValueAt(comboBox.getSelectedIndex(), row, column); } }); } control = comboBox; comboBox.setEnabled(!cell.isDisabled()); comp = comboBox; break; case LABEL: JLabel lbl = new JLabel(cell.getLabel()); comp = lbl; control = lbl; break; case CUSTOM: return new CustomCellEditorWrapper(cell, customEditors.get(col.getType())); default: final JTextField label = new JTextField((String) value); label.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent arg0) { SwingTree.this.table.setValueAt(label.getText(), row, column); } public void insertUpdate(DocumentEvent arg0) { SwingTree.this.table.setValueAt(label.getText(), row, column); } public void removeUpdate(DocumentEvent arg0) { SwingTree.this.table.setValueAt(label.getText(), row, column); } }); if (isSelected) { label.setOpaque(true); // label.setBackground(Color.LIGHT_GRAY); } control = label; comp = label; label.setEnabled(!cell.isDisabled()); label.setDisabledTextColor(Color.DARK_GRAY); break; } return comp; } @Override public Object getCellEditorValue() { if (control instanceof JCheckBox) { return ((JCheckBox) control).isSelected(); } else if (control instanceof JComboBox) { JComboBox box = (JComboBox) control; if (box.isEditable()) { return ((JTextComponent) box.getEditor().getEditorComponent()).getText(); } else { return box.getSelectedIndex(); } } else if (control instanceof JTextField) { return ((JTextField) control).getText(); } else { return ((JLabel) control).getText(); } } }; }
From source file:org.springframework.richclient.factory.DefaultComponentFactory.java
public void configureForEnum(JComboBox comboBox, Class enumType) { Collection enumValues = getEnumResolver().getLabeledEnumSet(enumType); if (logger.isDebugEnabled()) { logger.debug("Populating combo box model with enums of type '" + enumType.getName() + "'; enums are [" + enumValues + "]"); }//from w ww . j av a2 s. com CompoundComparator comparator = new CompoundComparator(); comparator.addComparator(LabeledEnum.LABEL_ORDER); comparator.addComparator(new ComparableComparator()); comboBox.setModel(new ComboBoxListModel(new ArrayList(enumValues), comparator)); comboBox.setRenderer(new LabeledEnumListRenderer(messageSource)); comboBox.setEditor(new LabeledEnumComboBoxEditor(messageSource, comboBox.getEditor())); }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Checks whether an input (query or connect string) is already in its * associated combo box. If not, the new information is added to the combo * list/*from w w w .j a v a 2s . co m*/ * * @param combo * JComboBox which has a list of the query statements or connect * strings. */ private void checkForNewString(JComboBox combo) { // String newString, foundString; Object newValue; int checkDups, matchAt; boolean match; // boolean newCommented, foundCommented; // newCommented = foundCommented = false; matchAt = -1; if (combo == querySelection) { newValue = new Query(queryText.getText(), whichModeValue()); // newString = queryText.getText(); // newString = newString.replace('\n', ' '); } else { // newString = (String)combo.getEditor().getItem(); newValue = combo.getEditor().getItem(); } // if (newString.startsWith(COMMENT_PREFIX)) { // newCommented = true; // newString = newString.substring(2); // } // if (newString.trim().length() > 0) { if (newValue.toString().length() > 0) { match = false; for (checkDups = 0; checkDups < combo.getItemCount() && !match; ++checkDups) { // if (combo == querySelection) { // foundString = ((Query)combo.getItemAt(checkDups)).getSQL(); // } else { // foundString = ((String)combo.getItemAt(checkDups)); // } // if (foundString.startsWith(COMMENT_PREFIX)) { // foundString = foundString.substring(2); // foundCommented = true; // } else { // foundCommented = false; // } // if (newString.equals(foundString)) { if (newValue.equals(combo.getItemAt(checkDups))) { match = true; if (combo == querySelection) { ((Query) combo.getItemAt(checkDups)).setMode(whichModeValue()); } combo.setSelectedIndex(checkDups); matchAt = checkDups; } } // if (newCommented) { // newString = COMMENT_PREFIX + newString; // } if (!match) { addToCombo(combo, newValue); if (combo == querySelection) { // addToCombo(combo, new Query(newString, whichModeValue())); combo.setSelectedIndex(combo.getModel().getSize() - 1); matchAt = combo.getSelectedIndex(); } } // if (foundCommented != newCommented) { // if (combo == querySelection) { // replaceInCombo(combo, matchAt, // new Query(newString, whichModeValue())); // } else { // replaceInCombo(combo, matchAt, newString); // } // } if (combo == querySelection) { if (((Query) newValue).isCommented() != ((Query) combo.getSelectedItem()).isCommented()) { replaceInCombo(combo, matchAt, newValue); } } } }