Example usage for javax.swing ComboBoxEditor getEditorComponent

List of usage examples for javax.swing ComboBoxEditor getEditorComponent

Introduction

In this page you can find the example usage for javax.swing ComboBoxEditor getEditorComponent.

Prototype

public Component getEditorComponent();

Source Link

Document

Returns the component that should be added to the tree hierarchy for this editor

Usage

From source file:Main.java

static JTextComponent getTextComponent(final Component component) {
    if (component instanceof JTextComponent) {
        return (JTextComponent) component;
    } else if (component instanceof JComboBox) {
        final JComboBox<?> comboBox = (JComboBox<?>) component;
        final ComboBoxEditor editor = comboBox.getEditor();
        final Component editorComponent = editor.getEditorComponent();
        return getTextComponent(editorComponent);
    } else {/*w  ww.  j  a  v a  2  s  .  c  o m*/
        return null;
    }
}

From source file:Main.java

public void setEditor(ComboBoxEditor anEditor) {
    super.setEditor(anEditor);
    if (anEditor.getEditorComponent() instanceof JTextField) {
        tf = (JTextField) anEditor.getEditorComponent();
        tf.addKeyListener(new KeyAdapter() {
            public void keyReleased(KeyEvent ev) {
                char key = ev.getKeyChar();
                if (!(Character.isLetterOrDigit(key) || Character.isSpaceChar(key))) {
                    return;
                }//w  ww .  ja  v  a  2 s  .c o m
                String s = tf.getText();
                caretPos = tf.getCaretPosition();
                try {
                    String text = tf.getText(0, caretPos);
                    int n = getItemCount();
                    for (int i = 0; i < n; i++) {
                        int ind = ((String) getItemAt(i)).indexOf(text);
                        if (ind == 0) {
                            setSelectedIndex(i);
                            return;
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
    }
}

From source file:edu.ku.brc.af.ui.db.JEditComboBox.java

@Override
public void setEditor(ComboBoxEditor anEditor) {
    super.setEditor(anEditor);

    if (anEditor != null && anEditor.getEditorComponent() instanceof JTextField) {
        textField = (JTextField) anEditor.getEditorComponent();

        FocusListener fl = createFocusListener();
        if (fl != null) {
            textField.addFocusListener(fl);
        }/*from   w  w w.  ja va 2  s. com*/

        KeyAdapter ka = createKeyAdapter();
        if (ka != null) {
            textField.addKeyListener(ka);
        }
    }
}

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  ww w. j  a va2s.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.eclipse.jubula.rc.swing.tester.adapter.JComboBoxAdapter.java

/**
 * @param component/*from w w  w. jav a 2  s.c  om*/
 *            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.CollectableComboBox.java

/**
 * @return the text component of the editor, if any.
 *///from w ww . j a  v  a 2  s  . c om
private Document getEditorDocument() {
    Document result = null;
    final ComboBoxEditor editor = getJComboBox().getEditor();
    if (editor != null) {
        final Component comp = editor.getEditorComponent();
        if (comp instanceof JTextComponent) {
            result = ((JTextComponent) comp).getDocument();
        }
    }
    return result;
}

From source file:org.nuclos.client.ui.collect.component.CollectableComboBox.java

@Override
public void setMnemonic(char cMnemonic) {
    super.setMnemonic(cMnemonic);
    final ComboBoxEditor editor = getJComboBox().getEditor();
    if (editor != null) {
        final Component comp = editor.getEditorComponent();
        if (comp instanceof JTextComponent) {
            ((JTextComponent) comp).setFocusAccelerator(cMnemonic);
        }//from  w  w w  .  j ava 2  s  .com
    }
}