Java Code Examples for javax.swing.ComboBoxEditor#getEditorComponent()
The following examples show how to use
javax.swing.ComboBoxEditor#getEditorComponent() .
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: AutoCompletionDocumentListener.java From rapidminer-studio with GNU Affero General Public License v3.0 | 8 votes |
/** * Initializes the ComboBoxInput variable * * @param ignored not used */ private void initComboBoxEditor(Object... ignored) { ComboBoxEditor editor = comboBox.getEditor(); if (editor == null) { return; } if (editor.getEditorComponent() instanceof JTextComponent) { if (comboBoxInput != null) { //Clear old listener comboBoxInput.getDocument().removeDocumentListener(this); comboBoxInput.removeFocusListener(focusChangeListener); comboBoxInput.removeKeyListener(updateOnEnterKey); } comboBoxInput = ((JTextComponent) editor.getEditorComponent()); comboBoxInput.getDocument().addDocumentListener(this); // workaround for java bug #6433257 comboBoxInput.addFocusListener(focusChangeListener); // allow enter to use current value comboBoxInput.addKeyListener(updateOnEnterKey); } }
Example 2
Source File: FlatComboBoxUI.java From FlatLaf with Apache License 2.0 | 6 votes |
@Override protected ComboBoxEditor createEditor() { ComboBoxEditor comboBoxEditor = super.createEditor(); Component editor = comboBoxEditor.getEditorComponent(); if( editor instanceof JTextField ) { JTextField textField = (JTextField) editor; textField.setColumns( editorColumns ); // assign a non-null and non-javax.swing.plaf.UIResource border to the text field, // otherwise it is replaced with default text field border when switching LaF // because javax.swing.plaf.basic.BasicComboBoxEditor.BorderlessTextField.setBorder() // uses "border instanceof javax.swing.plaf.basic.BasicComboBoxEditor.UIResource" // instead of "border instanceof javax.swing.plaf.UIResource" textField.setBorder( BorderFactory.createEmptyBorder() ); } return comboBoxEditor; }
Example 3
Source File: FindDialog.java From FancyBing with GNU General Public License v3.0 | 5 votes |
@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 4
Source File: ComboBoxAutoCompleteSupport.java From netbeans with Apache License 2.0 | 5 votes |
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 5
Source File: ComboBoxAutoCompleteSupport.java From netbeans with Apache License 2.0 | 5 votes |
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: AutoCompletionComboBox.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
public AutoCompletionComboBoxEditor(ComboBoxEditor editor) { if ((editor.getEditorComponent() instanceof JTextField)) { this.editor = editor; editorComponent = (JTextField) editor.getEditorComponent(); editorComponent.getDocument().addDocumentListener(docListener); editorComponent.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { setSelectedItem(editorComponent.getText()); actionPerformed(new ActionEvent(this, 0, "editingStoped")); e.consume(); } else if (e.getKeyCode() == KeyEvent.VK_TAB) { if (isPopupVisible()) { hidePopup(); } else { showPopup(); } e.consume(); } else { super.keyPressed(e); } } }); } else { throw new IllegalArgumentException("Only JTextField allowed as editor component"); } }
Example 7
Source File: AutoCompletionComboBox.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
@Override public void setEditor(ComboBoxEditor anEditor) { // check if editor component has changed at all: Otherwise listener already registered if (getEditor() == null || anEditor.getEditorComponent() != getEditor().getEditorComponent()) { super.setEditor(new AutoCompletionComboBoxEditor(anEditor)); } }
Example 8
Source File: ComboBoxCellEditor.java From cropplanning with GNU General Public License v3.0 | 5 votes |
public void propertyChange(PropertyChangeEvent e) { if (e.getPropertyName().equals("editor")) { ComboBoxEditor editor = comboBox.getEditor(); if (editor!=null && editor.getEditorComponent()!=null) { JComponent editorComponent = (JComponent) comboBox.getEditor().getEditorComponent(); editorComponent.addKeyListener(this); editorComponent.setBorder(null); } } }