javax.swing.ComboBoxEditor Java Examples
The following examples show how to use
javax.swing.ComboBoxEditor.
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: SeaGlassComboBoxUI.java From seaglass with Apache License 2.0 | 6 votes |
/** * Called when the combos editor changes * * @param evt * A PropertyChangeEvent object describing the event source * and the property that has changed. */ public void propertyChange(PropertyChangeEvent evt) { ComboBoxEditor newEditor = comboBox.getEditor(); if (editor != newEditor) { if (editorComponent != null) { editorComponent.removeFocusListener(this); } editor = newEditor; if (editor != null) { editorComponent = editor.getEditorComponent(); if (editorComponent != null) { editorComponent.addFocusListener(this); } } } }
Example #3
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 #4
Source File: CSearchExecuter.java From binnavi with Apache License 2.0 | 6 votes |
/** * Executes a search operation. * * @param parent Parent window used for dialogs. * @param editor Combobox editor whose color is changed depending on the search result. * @param graph Graph to search through. * @param searcher Executes the search over the graph. * @param searchString The string to search for. * @param cycleBackwards True, to cycle backwards through the results. False, to cycle in forward * order. * @param zoomToResult True, to zoom to a result. False, to move without zooming. */ public static void search(final Window parent, final ComboBoxEditor editor, final ZyGraph graph, final GraphSearcher searcher, final String searchString, final boolean cycleBackwards, final boolean zoomToResult) { // If something in the searcher changed, we have to recalculate // the search results. if (searcher.hasChanged() || !searchString.equals(searcher.getLastSearchString())) { CSearchExecuter.startNewSearch(parent, editor, graph, searcher, searchString, zoomToResult); } else if (!searcher.getResults().isEmpty()) // Don't bother cycling through an empty results // list { CSearchExecuter.cycleExistingSearch(parent, graph, searcher, cycleBackwards, zoomToResult); } }
Example #5
Source File: ParameterTupelCellEditor.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
private void constructPanel(String[] values) { // constructing editors editors = new PropertyValueCellEditor[types.length]; for (int i = 0; i < types.length; i++) { editors[i] = PropertyPanel.instantiateValueCellEditor(types[i], operator); } // building panel panel = new JPanel(); panel.setFocusable(true); panel.setLayout(new GridLayout(1, editors.length)); for (int i = 0; i < types.length; i++) { Component editorComponent = editors[i].getTableCellEditorComponent(null, values[i], false, 0, 0); if (editorComponent instanceof JComboBox) { if (((JComboBox<?>) editorComponent).isEditable()) { ComboBoxEditor editor = ((JComboBox<?>) editorComponent).getEditor(); if (editor instanceof BasicComboBoxEditor) { editor.getEditorComponent().addFocusListener(focusListener); } } else { editorComponent.addFocusListener(focusListener); } } else if (editorComponent instanceof JPanel) { JPanel editorPanel = (JPanel) editorComponent; Component[] components = editorPanel.getComponents(); for (Component comp : components) { comp.addFocusListener(focusListener); } } else { editorComponent.addFocusListener(focusListener); } panel.add(editorComponent); panel.addFocusListener(focusListener); } }
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: JComboBoxOperator.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Maps {@code JComboBox.setEditor(ComboBoxEditor)} through queue */ public void setEditor(final ComboBoxEditor comboBoxEditor) { runMapping(new MapVoidAction("setEditor") { @Override public void map() { ((JComboBox) getSource()).setEditor(comboBoxEditor); } }); }
Example #8
Source File: JComboBoxOperator.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Maps {@code JComboBox.getEditor()} through queue */ public ComboBoxEditor getEditor() { return (runMapping(new MapAction<ComboBoxEditor>("getEditor") { @Override public ComboBoxEditor map() { return ((JComboBox) getSource()).getEditor(); } })); }
Example #9
Source File: JComboBoxOperator.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Maps {@code JComboBox.configureEditor(ComboBoxEditor, Object)} * through queue */ public void configureEditor(final ComboBoxEditor comboBoxEditor, final Object object) { runMapping(new MapVoidAction("configureEditor") { @Override public void map() { ((JComboBox) getSource()).configureEditor(comboBoxEditor, object); } }); }
Example #10
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 #11
Source File: AnnotationSetNameComboEditor.java From gate-core with GNU Lesser General Public License v3.0 | 5 votes |
AnnotationSetNameComboEditor(ComboBoxEditor realEditor) { this.realEditor = realEditor; normalFont = realEditor.getEditorComponent().getFont(); italicFont = normalFont.deriveFont(Font.ITALIC); setItem(null, false); realEditor.getEditorComponent().addFocusListener(this); }
Example #12
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 #13
Source File: BEComboBoxUI.java From beautyeye with Apache License 2.0 | 5 votes |
/** * Creates the default editor that will be used in editable combo boxes. * A default editor will be used only if an editor has not been * explicitly set with <code>setEditor</code>. * * @return a <code>ComboBoxEditor</code> used for the combo box * @see javax.swing.JComboBox#setEditor */ protected ComboBoxEditor createEditor() { BasicComboBoxEditor.UIResource bcbe = new BasicComboBoxEditor.UIResource(); if(bcbe != null) { Component c = bcbe.getEditorComponent(); if(c != null) { //把默认的Editor设置成透明(editor不透明的话就会遮住NP背景图,从而使得外观难看) ((JComponent)c).setOpaque(false); //* 以下这段是为了给默认Editor加上border而加(没有它个border将使 //* 得与不可编辑comboBox的内容组件看起来有差异哦), //* 在WindowsComboBoxUI中,这段代码是放在WindowsComboBoxEditor //* 中的方法createEditorComponent中实现,由于该 方法是1.6里才有的, //* BE LNF因要兼容java1.5,所以不作类似实现就在本方法中实现也没有问题。 //* 类似实现请参考WindowsComboBoxUI.WindowsComboBoxEditor类 // JTextField editor = (JTextField)c; Border border = (Border)UIManager.get("ComboBox.editorBorder"); if (border != null) { ((JComponent)c).setBorder(border); } } } return bcbe; }
Example #14
Source File: SeaGlassComboBoxUI.java From seaglass with Apache License 2.0 | 5 votes |
@Override protected ComboBoxEditor createEditor() { // In case the combo box is editable we inherit the size variant to the editor. // TODO this needs to be done later to support client property override // because the editor is created in the ComboBox constructor already a later set of the property has no effect SynthComboBoxEditor result = new SynthComboBoxEditor(); String scaleKey = SeaGlassStyle.getSizeVariant(comboBox); if (scaleKey != null) { ((JComponent)result.getEditorComponent()).putClientProperty("JComponent.sizeVariant", scaleKey); } return result; }
Example #15
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 #16
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 #17
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); } } }
Example #18
Source File: AutoCompletionListener.java From jdal with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void keyReleased(KeyEvent e) { char ch = e.getKeyChar(); if (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch)) return; ComboBoxEditor editor = (ComboBoxEditor) combo.getEditor(); String editing = ((JTextField) editor.getEditorComponent()).getText(); combo.removeAllItems(); addList(getList(editing)); combo.setPopupVisible(true); ((JTextField) editor.getEditorComponent()).setText(editing); combo.repaint(); }
Example #19
Source File: ComboBoxUI.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
@Override protected ComboBoxEditor createEditor() { return new RapidLookComboBoxEditor.UIResource(); }
Example #20
Source File: Test8015300.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { UIManager.LookAndFeelInfo[] array = UIManager.getInstalledLookAndFeels(); for (UIManager.LookAndFeelInfo info : array) { UIManager.setLookAndFeel(info.getClassName()); System.err.println("L&F: " + info.getName()); invokeAndWait(new Runnable() { @Override public void run() { combo = new JComboBox<>(ITEMS); combo.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent event) { if (ItemEvent.SELECTED == event.getStateChange() && combo.isEditable()) { ComboBoxEditor editor = combo.getEditor(); Object component = editor.getEditorComponent(); if (component instanceof JTextField) { JTextField text = (JTextField) component; boolean selected = null != text.getSelectedText(); StringBuilder sb = new StringBuilder(); sb.append(" - ").append(combo.getSelectedIndex()); sb.append(": ").append(event.getItem()); if (selected) { sb.append("; selected"); } System.err.println(sb); if ((editor instanceof WindowsComboBoxEditor) == (null == text.getSelectedText())) { throw new Error("unexpected state of text selection"); } } } } }); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(combo); frame.pack(); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); } }); for (int i = 0; i < ITEMS.length; ++i) { select(i, true); select(1, false); } invokeAndWait(new Runnable() { @Override public void run() { windowForComponent(combo).dispose(); } }); } }
Example #21
Source File: Test8015300.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { UIManager.LookAndFeelInfo[] array = UIManager.getInstalledLookAndFeels(); for (UIManager.LookAndFeelInfo info : array) { UIManager.setLookAndFeel(info.getClassName()); System.err.println("L&F: " + info.getName()); invokeAndWait(new Runnable() { @Override public void run() { combo = new JComboBox<>(ITEMS); combo.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent event) { if (ItemEvent.SELECTED == event.getStateChange() && combo.isEditable()) { ComboBoxEditor editor = combo.getEditor(); Object component = editor.getEditorComponent(); if (component instanceof JTextField) { JTextField text = (JTextField) component; boolean selected = null != text.getSelectedText(); StringBuilder sb = new StringBuilder(); sb.append(" - ").append(combo.getSelectedIndex()); sb.append(": ").append(event.getItem()); if (selected) { sb.append("; selected"); } System.err.println(sb); if ((editor instanceof WindowsComboBoxEditor) == (null == text.getSelectedText())) { throw new Error("unexpected state of text selection"); } } } } }); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(combo); frame.pack(); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); } }); for (int i = 0; i < ITEMS.length; ++i) { select(i, true); select(1, false); } invokeAndWait(new Runnable() { @Override public void run() { windowForComponent(combo).dispose(); } }); } }
Example #22
Source File: Test8015300.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { UIManager.LookAndFeelInfo[] array = UIManager.getInstalledLookAndFeels(); for (UIManager.LookAndFeelInfo info : array) { UIManager.setLookAndFeel(info.getClassName()); System.err.println("L&F: " + info.getName()); invokeAndWait(new Runnable() { @Override public void run() { combo = new JComboBox<>(ITEMS); combo.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent event) { if (ItemEvent.SELECTED == event.getStateChange() && combo.isEditable()) { ComboBoxEditor editor = combo.getEditor(); Object component = editor.getEditorComponent(); if (component instanceof JTextField) { JTextField text = (JTextField) component; boolean selected = null != text.getSelectedText(); StringBuilder sb = new StringBuilder(); sb.append(" - ").append(combo.getSelectedIndex()); sb.append(": ").append(event.getItem()); if (selected) { sb.append("; selected"); } System.err.println(sb); if ((editor instanceof WindowsComboBoxEditor) == (null == text.getSelectedText())) { throw new Error("unexpected state of text selection"); } } } } }); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(combo); frame.pack(); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); } }); for (int i = 0; i < ITEMS.length; ++i) { select(i, true); select(1, false); } invokeAndWait(new Runnable() { @Override public void run() { windowForComponent(combo).dispose(); } }); } }
Example #23
Source File: ComboBoxEditorWrapper.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
ComboBoxEditorWrapper(ComboBoxEditor wrapped) { if (wrapped == null) { throw new IllegalArgumentException("wrapped ComboBoxEditor must not be null"); } this.wrapped = wrapped; }
Example #24
Source File: Test8015300.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { UIManager.LookAndFeelInfo[] array = UIManager.getInstalledLookAndFeels(); for (UIManager.LookAndFeelInfo info : array) { UIManager.setLookAndFeel(info.getClassName()); System.err.println("L&F: " + info.getName()); invokeAndWait(new Runnable() { @Override public void run() { combo = new JComboBox<>(ITEMS); combo.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent event) { if (ItemEvent.SELECTED == event.getStateChange() && combo.isEditable()) { ComboBoxEditor editor = combo.getEditor(); Object component = editor.getEditorComponent(); if (component instanceof JTextField) { JTextField text = (JTextField) component; boolean selected = null != text.getSelectedText(); StringBuilder sb = new StringBuilder(); sb.append(" - ").append(combo.getSelectedIndex()); sb.append(": ").append(event.getItem()); if (selected) { sb.append("; selected"); } System.err.println(sb); if ((editor instanceof WindowsComboBoxEditor) == (null == text.getSelectedText())) { throw new Error("unexpected state of text selection"); } } } } }); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(combo); frame.pack(); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); } }); for (int i = 0; i < ITEMS.length; ++i) { select(i, true); select(1, false); } invokeAndWait(new Runnable() { @Override public void run() { windowForComponent(combo).dispose(); } }); } }
Example #25
Source File: Test8015300.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { UIManager.LookAndFeelInfo[] array = UIManager.getInstalledLookAndFeels(); for (UIManager.LookAndFeelInfo info : array) { UIManager.setLookAndFeel(info.getClassName()); System.err.println("L&F: " + info.getName()); invokeAndWait(new Runnable() { @Override public void run() { combo = new JComboBox<>(ITEMS); combo.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent event) { if (ItemEvent.SELECTED == event.getStateChange() && combo.isEditable()) { ComboBoxEditor editor = combo.getEditor(); Object component = editor.getEditorComponent(); if (component instanceof JTextField) { JTextField text = (JTextField) component; boolean selected = null != text.getSelectedText(); StringBuilder sb = new StringBuilder(); sb.append(" - ").append(combo.getSelectedIndex()); sb.append(": ").append(event.getItem()); if (selected) { sb.append("; selected"); } System.err.println(sb); if ((editor instanceof WindowsComboBoxEditor) == (null == text.getSelectedText())) { throw new Error("unexpected state of text selection"); } } } } }); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(combo); frame.pack(); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); } }); for (int i = 0; i < ITEMS.length; ++i) { select(i, true); select(1, false); } invokeAndWait(new Runnable() { @Override public void run() { windowForComponent(combo).dispose(); } }); } }
Example #26
Source File: AutoCompleteDecorator.java From cropplanning with GNU General Public License v3.0 | 4 votes |
/** * Enables automatic completion for the given JComboBox. The automatic * completion will be strict (only items from the combo box can be selected) * if the combo box is not editable. * @param comboBox a combo box * @param stringConverter the converter used to transform items to strings */ public static void decorate(final JComboBox comboBox, final ObjectToStringConverter stringConverter) { boolean strictMatching = !comboBox.isEditable(); // has to be editable comboBox.setEditable(true); // fix the popup location AquaLnFPopupLocationFix.install(comboBox); // configure the text component=editor component JTextComponent editorComponent = (JTextComponent) comboBox.getEditor().getEditorComponent(); final AbstractAutoCompleteAdaptor adaptor = new ComboBoxAdaptor(comboBox); final AutoCompleteDocument document = new AutoCompleteDocument(adaptor, strictMatching, stringConverter); decorate(editorComponent, document, adaptor); // show the popup list when the user presses a key final KeyListener keyListener = new KeyAdapter() { public void keyPressed(KeyEvent keyEvent) { // don't popup on action keys (cursor movements, etc...) if (keyEvent.isActionKey()) return; // don't popup if the combobox isn't visible anyway if (comboBox.isDisplayable() && !comboBox.isPopupVisible()) { int keyCode = keyEvent.getKeyCode(); // don't popup when the user hits shift,ctrl or alt if (keyCode==keyEvent.VK_SHIFT || keyCode==keyEvent.VK_CONTROL || keyCode==keyEvent.VK_ALT) return; // don't popup when the user hits escape (see issue #311) if (keyCode==keyEvent.VK_ESCAPE) return; comboBox.setPopupVisible(true); } } }; editorComponent.addKeyListener(keyListener); if (stringConverter!=ObjectToStringConverter.DEFAULT_IMPLEMENTATION) { comboBox.setEditor(new AutoCompleteComboBoxEditor(comboBox.getEditor(), stringConverter)); } // Changing the l&f can change the combobox' editor which in turn // would not be autocompletion-enabled. The new editor needs to be set-up. comboBox.addPropertyChangeListener("editor", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { ComboBoxEditor editor = (ComboBoxEditor) e.getNewValue(); if (editor!=null && editor.getEditorComponent()!=null) { if (!(editor instanceof AutoCompleteComboBoxEditor) && stringConverter!=ObjectToStringConverter.DEFAULT_IMPLEMENTATION) { comboBox.setEditor(new AutoCompleteComboBoxEditor(editor, stringConverter)); // Don't do the decorate step here because calling setEditor will trigger // the propertychange listener a second time, which will do the decorate // and addKeyListener step. } else { decorate((JTextComponent) editor.getEditorComponent(), document, adaptor); editor.getEditorComponent().addKeyListener(keyListener); } } } }); }
Example #27
Source File: RuntimeComboBox.java From netbeans with Apache License 2.0 | 4 votes |
public void configureEditor(ComboBoxEditor anEditor, Object anItem) { combo.configureEditor(anEditor, anItem); }
Example #28
Source File: Test8015300.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { UIManager.LookAndFeelInfo[] array = UIManager.getInstalledLookAndFeels(); for (UIManager.LookAndFeelInfo info : array) { UIManager.setLookAndFeel(info.getClassName()); System.err.println("L&F: " + info.getName()); invokeAndWait(new Runnable() { @Override public void run() { combo = new JComboBox<>(ITEMS); combo.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent event) { if (ItemEvent.SELECTED == event.getStateChange() && combo.isEditable()) { ComboBoxEditor editor = combo.getEditor(); Object component = editor.getEditorComponent(); if (component instanceof JTextField) { JTextField text = (JTextField) component; boolean selected = null != text.getSelectedText(); StringBuilder sb = new StringBuilder(); sb.append(" - ").append(combo.getSelectedIndex()); sb.append(": ").append(event.getItem()); if (selected) { sb.append("; selected"); } System.err.println(sb); if ((editor instanceof WindowsComboBoxEditor) == (null == text.getSelectedText())) { throw new Error("unexpected state of text selection"); } } } } }); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(combo); frame.pack(); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); } }); for (int i = 0; i < ITEMS.length; ++i) { select(i, true); select(1, false); } invokeAndWait(new Runnable() { @Override public void run() { windowForComponent(combo).dispose(); } }); } }
Example #29
Source File: Test8015300.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { UIManager.LookAndFeelInfo[] array = UIManager.getInstalledLookAndFeels(); for (UIManager.LookAndFeelInfo info : array) { UIManager.setLookAndFeel(info.getClassName()); System.err.println("L&F: " + info.getName()); invokeAndWait(new Runnable() { @Override public void run() { combo = new JComboBox<>(ITEMS); combo.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent event) { if (ItemEvent.SELECTED == event.getStateChange() && combo.isEditable()) { ComboBoxEditor editor = combo.getEditor(); Object component = editor.getEditorComponent(); if (component instanceof JTextField) { JTextField text = (JTextField) component; boolean selected = null != text.getSelectedText(); StringBuilder sb = new StringBuilder(); sb.append(" - ").append(combo.getSelectedIndex()); sb.append(": ").append(event.getItem()); if (selected) { sb.append("; selected"); } System.err.println(sb); if ((editor instanceof WindowsComboBoxEditor) == (null == text.getSelectedText())) { throw new Error("unexpected state of text selection"); } } } } }); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(combo); frame.pack(); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); } }); for (int i = 0; i < ITEMS.length; ++i) { select(i, true); select(1, false); } invokeAndWait(new Runnable() { @Override public void run() { windowForComponent(combo).dispose(); } }); } }
Example #30
Source File: Test8015300.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { UIManager.LookAndFeelInfo[] array = UIManager.getInstalledLookAndFeels(); for (UIManager.LookAndFeelInfo info : array) { UIManager.setLookAndFeel(info.getClassName()); System.err.println("L&F: " + info.getName()); invokeAndWait(new Runnable() { @Override public void run() { combo = new JComboBox<>(ITEMS); combo.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent event) { if (ItemEvent.SELECTED == event.getStateChange() && combo.isEditable()) { ComboBoxEditor editor = combo.getEditor(); Object component = editor.getEditorComponent(); if (component instanceof JTextField) { JTextField text = (JTextField) component; boolean selected = null != text.getSelectedText(); StringBuilder sb = new StringBuilder(); sb.append(" - ").append(combo.getSelectedIndex()); sb.append(": ").append(event.getItem()); if (selected) { sb.append("; selected"); } System.err.println(sb); if ((editor instanceof WindowsComboBoxEditor) == (null == text.getSelectedText())) { throw new Error("unexpected state of text selection"); } } } } }); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(combo); frame.pack(); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); } }); for (int i = 0; i < ITEMS.length; ++i) { select(i, true); select(1, false); } invokeAndWait(new Runnable() { @Override public void run() { windowForComponent(combo).dispose(); } }); } }