Example usage for javax.swing JComboBox getEditor

List of usage examples for javax.swing JComboBox getEditor

Introduction

In this page you can find the example usage for javax.swing JComboBox getEditor.

Prototype

public ComboBoxEditor getEditor() 

Source Link

Document

Returns the editor used to paint and edit the selected item in the JComboBox field.

Usage

From source file:Main.java

public void actionPerformed(ActionEvent e) {
    JComboBox jcb = (JComboBox) e.getSource();
    System.out.println("down action");
    ComboBoxUI ui = jcb.getUI();//from  w w w  .  j  a  v a  2 s .  com

    if (ui.isPopupVisible(jcb)) {
        int i = jcb.getSelectedIndex();
        if (i < jcb.getModel().getSize() - 1) {
            jcb.setSelectedIndex(i + 1);
            jcb.repaint();
        }
    } else {
        int nItems = jcb.getItemCount();

        ComboBoxEditor cbe = jcb.getEditor();

        String st; // Search text

        st = ((String) cbe.getItem()).toUpperCase();

        for (int i = 0; i < nItems; i++) {
            String item = ((String) jcb.getItemAt(i)).toUpperCase();

            if (item.startsWith(st)) {
                jcb.setSelectedIndex(i);
                break;
            }
        }

        ui.setPopupVisible(jcb, true);
    }
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static <T> JComboBox<T> createComboBox(T[] values, JFormattedTextField textField,
        DocumentListener... docListeners) {
    JComboBox<T> cbox = new JComboBox<T>(values);
    cbox.setUI(new IntelComboBoxUI());
    FormattedComboBoxEditor editor = new FormattedComboBoxEditor(textField);
    cbox.setEditable(true);//from   w ww .ja v a  2  s.c  o  m
    cbox.setEditor(editor);

    // Get the text editor for this combo box
    final JTextComponent tc = (JTextComponent) cbox.getEditor().getEditorComponent();

    // Initialize the document listeners
    for (DocumentListener docListener : docListeners) {
        tc.getDocument().addDocumentListener(docListener);
    }
    return cbox;
}

From source file:eu.europa.ec.markt.tlmanager.view.binding.BindingManager.java

/**
 * Creates the binding for component./*w w  w .j ava 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:com.intel.stl.ui.common.view.ComponentFactory.java

public static JComboBox<String> createComboBox(String[] strArray, DocumentListener... docListeners) {

    JComboBox<String> cbox = new JComboBox<String>(strArray) {
        private static final long serialVersionUID = -7465791917624978560L;

        @Override//from www.j a v a  2 s  .  com
        public String toString() {
            return "JComboBox@" + StringUtils.intHexString(hashCode());
        }
    };
    cbox.setUI(new IntelComboBoxUI());

    // Get the text editor for this combo box
    JTextComponent tc = (JTextComponent) cbox.getEditor().getEditorComponent();

    // Initialize the document listeners
    for (DocumentListener docListener : docListeners) {
        tc.getDocument().addDocumentListener(docListener);
    }
    return cbox;
}

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 w w. j  a va  2s  .  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   ww  w .ja  va 2 s . c o  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:com.sec.ose.osi.ui.frm.main.manage.dialog.JDlgProjectCreate.java

private void refresh(JComboBox<String> jComboBoxClonedFrom) {
    jComboBoxClonedFrom.removeAllItems();

    if (names != null) {
        jComboBoxClonedFrom.addItem("");
        for (String name : names) {
            jComboBoxClonedFrom.addItem(name);
        }/*from ww w . j av  a2  s .  c  o m*/
    }
    ((JTextField) jComboBoxClonedFrom.getEditor().getEditorComponent()).setText("");
}

From source file:io.github.jeddict.jpa.modeler.source.generator.ui.GenerateCodeDialog.java

public String getPackage(JComboBox packageCombo) {
    return ((JTextComponent) packageCombo.getEditor().getEditorComponent()).getText();
}

From source file:king.flow.action.DefaultMsgSendAction.java

protected void showDoneMsg(final TLSResult result) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override//from  w  w w .  j a v  a2 s. com
        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:io.github.jeddict.jpa.modeler.source.generator.ui.GenerateCodeDialog.java

private void setPackage(JComboBox packageCombo, String _package) {
    ComboBoxModel model = packageCombo.getModel();
    for (int i = 0; i < model.getSize(); i++) {
        if (model.getElementAt(i).toString().equals(_package)) {
            model.setSelectedItem(model.getElementAt(i));
            return;
        }//from   w w w.j  av  a2  s  .c  o m
    }
    ((JTextComponent) packageCombo.getEditor().getEditorComponent()).setText(_package);
}