Java Code Examples for javax.swing.JComboBox#getEditor()

The following examples show how to use javax.swing.JComboBox#getEditor() . 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: FindDialog.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private JPanel createInputPanel()
{
    JPanel outerPanel = new JPanel(new BorderLayout());
    JPanel innerPanel = new JPanel(new BorderLayout());
    m_comboBox = new JComboBox(getHistory().toArray());
    StringBuilder prototype = new StringBuilder(70);
    for (int i = 0; i < 40; ++i)
        prototype.append('-');
    m_comboBox.setPrototypeDisplayValue(prototype.toString());
    m_comboBox.setEditable(true);
    ComboBoxEditor editor = m_comboBox.getEditor();
    m_comboBox.addActionListener(this);
    m_textField = (JTextField)editor.getEditorComponent();
    m_textField.selectAll();
    KeyListener keyListener = new KeyAdapter()
        {
            public void keyPressed(KeyEvent e)
            {
                int c = e.getKeyCode();
                if (c == KeyEvent.VK_ESCAPE
                    && ! m_comboBox.isPopupVisible())
                    dispose();
            }
        };
    m_textField.addKeyListener(keyListener);
    GuiUtil.setMonospacedFont(m_comboBox);
    innerPanel.add(m_comboBox, BorderLayout.CENTER);
    outerPanel.add(innerPanel, BorderLayout.NORTH);
    return outerPanel;
}
 
Example 2
Source File: ReturnTypeUIHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void setSelectedItem(final JComboBox combo, final Object item) {
    combo.setSelectedItem(item);
    if (combo.isEditable() && combo.getEditor() != null) {
        // item must be set in the editor in case of editable combobox
        combo.configureEditor(combo.getEditor(), combo.getSelectedItem()); 
    }
}
 
Example 3
Source File: ComboBoxAutoCompleteSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static boolean install( JComboBox combo ) {
    boolean res = false;
    ComboBoxEditor comboEditor = combo.getEditor();
    if( comboEditor.getEditorComponent() instanceof JTextComponent ) {
        JTextComponent textEditor = ( JTextComponent ) comboEditor.getEditorComponent();
        Document doc = textEditor.getDocument();
        doc.addDocumentListener( new AutoCompleteListener( combo ) );
        setIgnoreSelectionEvents( combo, false );
        combo.setEditable( true );
        res = true;
    }
    combo.putClientProperty( "nb.combo.autocomplete", res ); //NOI18N
    return res;
}
 
Example 4
Source File: DatasourceUIHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void setSelectedItem(final JComboBox combo, final Object item) {
    combo.setSelectedItem(item);
    if (combo.isEditable() && combo.getEditor() != null) {
        // item must be set in the editor in case of editable combobox
        combo.configureEditor(combo.getEditor(), combo.getSelectedItem()); 
    }
}
 
Example 5
Source File: ComboBoxAutoCompleteSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static boolean install( JComboBox combo ) {
    boolean res = false;
    ComboBoxEditor comboEditor = combo.getEditor();
    if( comboEditor.getEditorComponent() instanceof JTextComponent ) {
        JTextComponent textEditor = ( JTextComponent ) comboEditor.getEditorComponent();
        Document doc = textEditor.getDocument();
        doc.addDocumentListener( new AutoCompleteListener( combo ) );
        setIgnoreSelectionEvents( combo, false );
        combo.setEditable( true );
        res = true;
    }
    combo.putClientProperty( "nb.combo.autocomplete", res ); //NOI18N
    return res;
}
 
Example 6
Source File: SeaGlassComboBoxUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
private EditorFocusHandler(JComboBox comboBox) {
    this.comboBox = comboBox;
    editor = comboBox.getEditor();
    if (editor != null) {
        editorComponent = editor.getEditorComponent();
        if (editorComponent != null) {
            editorComponent.addFocusListener(this);
        }
    }
    comboBox.addPropertyChangeListener("editor", this);
}