List of usage examples for javax.swing JComboBox isEditable
boolean isEditable
To view the source code for javax.swing JComboBox isEditable.
Click Source Link
From source file:Main.java
public Main() { JComboBox jc = new JComboBox(); jc.addItem("France"); jc.addItem("Germany"); jc.addItem("Italy"); jc.addItem("Japan"); jc.addItemListener(this); add(jc);// w w w .ja v a 2 s . c om System.out.println(jc.isEditable()); }
From source file:king.flow.action.business.InsertCardAction.java
private void showOnComponent(int componentId, String value) { Component meta = (Component) getBlockMeta(componentId); getLogger(InsertCardAction.class.getName()).log(Level.INFO, "Display component[{0}] type : {1}", new Object[] { String.valueOf(meta.getId()), meta.getType().value() }); switch (meta.getType()) { case LABEL:// w w w.ja v a2 s .c o m JLabel label = getBlock(meta.getId(), JLabel.class); label.setText(StringEscapeUtils.unescapeHtml(value)); break; case TEXT_FIELD: JTextField textField = getBlock(meta.getId(), JTextField.class); textField.setText(value); break; case COMBO_BOX: JComboBox combo = getBlock(meta.getId(), JComboBox.class); if (combo.isEditable()) { combo.getEditor().setItem(value); } break; default: getLogger(InsertCardAction.class.getName()).log(Level.WARNING, "Unsupported showed component type : {0}", meta.getType()); } }
From source file:eu.europa.ec.markt.tlmanager.view.pages.TreeDataPublisher.java
/** * This method handles the state of the <code>JLabel</code>'s that are associated to mandatory fields, as well as * any 'special' component. It is called via two tracks: Once by the implementation of the * <code>BindingListener</code> in <code>BindingManager</code> and once by individual action listeners for each * component. These action listeners are installed at the same time of the installation of the binding (cf. * BindingManager.setupComponent()).//from w ww. ja va 2s . c o m * * @param component the component * @param failure if the label should express a failure */ protected void changeMandatoryComponents(Component component, boolean failure) { if (mandatoryLabels == null) { return; } for (JLabel label : mandatoryLabels) { if (label == null || component == null || label.getLabelFor() == null) { continue; } if (label.getLabelFor().equals(component)) { boolean empty = false; if (component instanceof JTextField) { JTextField tf = (JTextField) component; if (tf.getText().isEmpty()) { empty = true; } } else if (component instanceof JComboBox) { JComboBox box = (JComboBox) component; if (box.isEditable()) { final String text = ((JTextComponent) box.getEditor().getEditorComponent()).getText(); if (StringUtils.isEmpty(text) || StringUtils.equals(text, Util.DEFAULT_NO_SELECTION_ENTRY)) { empty = true; } } else { if (box.getSelectedItem().equals(Util.DEFAULT_NO_SELECTION_ENTRY)) { empty = true; } } } else if (component instanceof JXDatePicker) { JXDatePicker picker = (JXDatePicker) component; Date date = picker.getDate(); if (date == null) { empty = true; } } else if (component instanceof DateTimePicker) { DateTimePicker picker = (DateTimePicker) component; Date date = picker.getDateTime(); if (date == null) { empty = true; } } else if (component instanceof MultivalueButton) { MultivalueButton button = (MultivalueButton) component; if (button.getMultivaluePanel().getMultivalueModel().isEmpty()) { empty = true; } } else if (component instanceof CertificateProperty) { CertificateProperty certificateProperty = (CertificateProperty) component; empty = certificateProperty.isEmpty(); } if (failure || empty) { label.setForeground(Configuration.MANDATORY_COLOR); } else { label.setForeground(Configuration.NORMAL_COLOR); } break; } } }
From source file:eu.europa.ec.markt.tlmanager.view.binding.BindingManager.java
/** * Creates the binding for component.//from w ww. j a v a 2 s . c o m * * @param component the component * @param sourceBeanProperty the source bean property * @param name the name */ public void createBindingForComponent(JComponent component, String sourceBeanProperty, String name) { LOG.fine("Create binding for " + component + " on " + sourceBeanProperty + " with name " + name); if (component instanceof JComboBox) { JComboBox jComboBox = (JComboBox) component; if (jComboBox.isEditable()) { component = (JComponent) jComboBox.getEditor().getEditorComponent(); } } BeanProperty bp = setupComponent(component); if (bp != null) { Binding binding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, null, BeanProperty.create(sourceBeanProperty), // bean component, bp, name); // ui bindings.put(name, binding); binding.addBindingListener(this); } else { LOG.log(Level.SEVERE, ">>>Unable to determine type of given component {0} - No BeanProperty could be set!", component); } }
From source file:king.flow.action.DefaultMsgSendAction.java
private Map<Integer, String> retrieveConditionValues(boolean cleanCargo) { HashMap<Integer, String> contents = new HashMap<>(); for (Condition<JComponent, Component> condition : conditions) { String value = null;//from w ww . java 2 s. c o m int id = condition.getMeta().getId(); switch (condition.getMeta().getType()) { case TEXT_FIELD: JTextField jtf = (JTextField) condition.getComponent(); value = jtf.getText(); contents.put(id, value); break; case COMBO_BOX: JComboBox jcb = (JComboBox) condition.getComponent(); if (jcb.isEditable()) { value = jcb.getEditor().getItem().toString(); } else { value = jcb.getSelectedItem() == null ? null : jcb.getSelectedItem().toString(); } contents.put(id, value); break; case DATE: JXDatePicker jxdp = (JXDatePicker) condition.getComponent(); value = CommonUtil.toStringDate(jxdp.getDate()); contents.put(id, value); break; case PASSWORD_FIELD: boolean isEncryption = false; List<Action> action = condition.getMeta().getAction(); for (Action actionConf : action) { if (actionConf.getEncryptKeyboardAction() != null) { isEncryption = true; break; } } if (isEncryption) { getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO, "use encrypted keyboard mode"); value = CommonUtil.retrieveCargo(Integer.toString(id)); //check notnull condition calling this method, so cannot clean pinblock if (cleanCargo) { CommonUtil.cleanTranStation(Integer.toString(id)); } } else { getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO, "use normal keyboard mode"); JPasswordField jpf = (JPasswordField) condition.getComponent(); final String unwrapped = new String(jpf.getPassword()); if (unwrapped.length() > 0) { try { value = CommonUtil.inputString(unwrapped); } catch (Throwable e) { getLogger(DefaultMsgSendAction.class.getName()).log(Level.WARNING, "crypto keyboard is out of work due to\n {0}", shapeErrPrompt(e)); value = unwrapped; } } else { value = unwrapped; } } contents.put(id, value); break; default: getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO, "Ignore useless component is : {0}", condition.getMeta().getType().value()); break; } } return contents; }
From source file:eu.europa.ec.markt.tlmanager.view.binding.BindingManager.java
private void addListenerForEditableCombobox(final JComboBox jComboBox, final EditableComboboxListener listener) { jComboBox.addActionListener(new ActionListener() { @Override/*from w w w .j ava 2 s . co m*/ public void actionPerformed(ActionEvent arg0) { final Object selectedItem = jComboBox.getSelectedItem(); listener.itemChanged(selectedItem); } }); if (jComboBox.isEditable()) { ((JTextComponent) jComboBox.getEditor().getEditorComponent()).getDocument() .addDocumentListener(new DefaultDocumentListener() { protected void changed() { final Object item = jComboBox.getEditor().getItem(); listener.itemChanged(item); } }); } }
From source file:king.flow.action.DefaultMsgSendAction.java
protected void showDoneMsg(final TLSResult result) { SwingUtilities.invokeLater(new Runnable() { @Override/*ww w .j av a 2 s.c o m*/ public void run() { if (doneDisplayList.size() == 1) { showOnComponent(getBlockMeta(doneDisplayList.get(0)), result); } else { try { JSONParser jsonParser = new JSONParser(); Object element = jsonParser.parse(result.getOkMsg()); if (element instanceof JSONArray) { JSONArray jsonArray = (JSONArray) element; int len = Integer.min(doneDisplayList.size(), jsonArray.size()); for (int i = 0; i < len; i++) { TLSResult freshResult = new TLSResult(result.getRetCode(), jsonArray.get(i).toString(), result.getErrMsg(), result.getPrtMsg()); showOnComponent(getBlockMeta(doneDisplayList.get(i)), freshResult); } } else { showOnComponent(getBlockMeta(doneDisplayList.get(0)), result); } } catch (Exception e) { getLogger(DefaultMsgSendAction.class.getName()).log(Level.WARNING, "Exception encounters during successful json value parsing : \n{0}", e); } } CommonUtil.cachePrintMsg(result.getPrtMsg()); if (result.getRedirection() != null) { String redirection = result.getRedirection(); getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO, "Be forced to jump to page[{0}], ignore designated page[{1}]", new Object[] { redirection, String.valueOf(next.getNextPanel()) }); int forwardPage = 0; try { forwardPage = Integer.parseInt(redirection); } catch (Exception e) { panelJump(next.getNextPanel()); return; } Object blockMeta = getBlockMeta(forwardPage); if (blockMeta == null || !(blockMeta instanceof Panel)) { getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO, "Be forced to jump to page[{0}], but page[{0}] is invalid Panel type. It is type[{1}]", new Object[] { redirection, (blockMeta == null ? "NULL" : blockMeta.getClass().getSimpleName()) }); panelJump(next.getNextPanel()); return; } panelJump(forwardPage); } else { panelJump(next.getNextPanel()); //trigger the action denoted in sendMsgAction Integer trigger = next.getTrigger(); if (trigger != null && getBlockMeta(trigger) != null) { final Component blockMeta = (Component) getBlockMeta(trigger); switch (blockMeta.getType()) { case COMBO_BOX: JComboBox comboBlock = getBlock(trigger, JComboBox.class); ItemListener[] itemListeners = comboBlock.getItemListeners(); ItemEvent e = new ItemEvent(comboBlock, ItemEvent.ITEM_STATE_CHANGED, comboBlock.getItemAt(comboBlock.getItemCount() - 1).toString(), ItemEvent.SELECTED); for (ItemListener itemListener : itemListeners) { itemListener.itemStateChanged(e);//wait and hang on util progress dialog gets to dispose } if (comboBlock.isEditable()) { String value = comboBlock.getEditor().getItem().toString(); if (value.length() == 0) { return; } } break; case BUTTON: JButton btnBlock = getBlock(trigger, JButton.class); btnBlock.doClick(); break; default: getLogger(DefaultMsgSendAction.class.getName()).log(Level.WARNING, "Invalid trigger component[{0}] as unsupported type[{1}]", new Object[] { trigger, blockMeta.getType() }); break; } } //trigger dealing //keep next cursor on correct component Integer nextCursor = next.getNextCursor(); if (nextCursor != null && getBlockMeta(nextCursor) != null) { JComponent block = getBlock(nextCursor, JComponent.class); block.requestFocusInWindow(); } } // no redirection branch } }); }
From source file:org.eclipse.jubula.rc.swing.listener.RecordActions.java
/** * creates CAP for Actions Replace Text/* w ww . j a v a2 s.com*/ * @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.gcaldaemon.gui.config.MainConfig.java
public static final boolean selectItem(JComboBox combo, String value) { if (value == null || combo == null || value.length() == 0) { return false; }//from w w w . j a v a 2 s . c om ComboBoxModel model = combo.getModel(); if (model != null) { int n, size = model.getSize(); n = value.indexOf(" - "); if (n != -1) { value = value.substring(n + 3); } String test; for (int i = 0; i < size; i++) { test = (String) model.getElementAt(i); if (test != null) { n = test.indexOf(" - "); if (n != -1) { test = test.substring(n + 3); } if (test.equals(value)) { combo.setSelectedIndex(i); combo.setToolTipText((String) model.getElementAt(i)); return true; } } } } if (combo.isEditable()) { combo.setSelectedItem(value); combo.setToolTipText(value); return true; } return false; }
From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java
private TableCellEditor getCellEditor(final SwingTreeCol col) { return new DefaultCellEditor(new JComboBox()) { JComponent control;/* w ww. jav a 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(); } } }; }