Java Code Examples for javax.swing.JComboBox#setPopupVisible()
The following examples show how to use
javax.swing.JComboBox#setPopupVisible() .
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: ReturnTypeUIHelper.java From netbeans with Apache License 2.0 | 5 votes |
private static void performBrowseType(final JComboBox combo, final ClasspathInfo cpInfo) { final ReturnTypeComboBoxModel model = (ReturnTypeComboBoxModel) combo.getModel(); combo.setPopupVisible(false); SwingUtilities.invokeLater(new Runnable() { public void run() { final ElementHandle<TypeElement> handle = TypeElementFinder.find(cpInfo, new TypeElementFinder.Customizer() { public Set<ElementHandle<TypeElement>> query(ClasspathInfo classpathInfo, String textForQuery, NameKind nameKind, Set<SearchScope> searchScopes) {//GEN-LAST:event_browseButtonActionPerformed return classpathInfo.getClassIndex().getDeclaredTypes(textForQuery, nameKind, searchScopes); } public boolean accept(ElementHandle<TypeElement> typeHandle) { return true; } }); combo.setPopupVisible(false); if (handle == null) { SwingUtilities.invokeLater(new Runnable() { public void run() { setSelectedItem(combo, model.getPreviousItem()); } }); } else { setSelectedItem(combo, handle.getQualifiedName()); } } }); }
Example 2
Source File: FixDuplicateImportStmts.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof JComboBox) { JComboBox combo = (JComboBox) e.getSource(); combo.setPopupVisible(!combo.isPopupVisible()); } }
Example 3
Source File: FixDuplicateImportStmts.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof JComboBox) { JComboBox combo = (JComboBox) e.getSource(); combo.setPopupVisible(!combo.isPopupVisible()); } }
Example 4
Source File: DataComboBoxSupport.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { final JComboBox comboBox = (JComboBox)e.getSource(); Object selectedItem = comboBox.getSelectedItem(); if (selectedItem == NEW_ITEM) { performingNewItemAction = true; try { comboBox.setPopupVisible(false); dataModel.newItemActionPerformed(); } finally { performingNewItemAction = false; } setPreviousNonSpecialItem(comboBox); // we (or maybe the client) have just selected an item inside an actionPerformed event, // which will not send another actionPerformed event for the new item. // We need to make sure all listeners get an event for the new item, // thus... final Object newSelectedItem = comboBox.getSelectedItem(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { comboBox.setSelectedItem(newSelectedItem); } }); } }
Example 5
Source File: ResolveDeclarationsPanel.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof JComboBox) { JComboBox combo = (JComboBox) e.getSource(); combo.setPopupVisible(!combo.isPopupVisible()); } }
Example 6
Source File: FixDuplicateImportStmts.java From netbeans with Apache License 2.0 | 4 votes |
public void actionPerformed(ActionEvent e) { if( e.getSource() instanceof JComboBox ) { JComboBox combo = (JComboBox)e.getSource(); combo.setPopupVisible( !combo.isPopupVisible() ); } }
Example 7
Source File: ImportChooserInnerPanel.java From netbeans with Apache License 2.0 | 4 votes |
public void actionPerformed(ActionEvent e) { if( e.getSource() instanceof JComboBox ) { JComboBox combo = (JComboBox)e.getSource(); combo.setPopupVisible( !combo.isPopupVisible() ); } }
Example 8
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); } } } }); }