/** * Sets the combo box which this object is auto completing and updates the * drop down list with the auto completion for the currently selected item. * * @param comboBox The combo box to enable browsing for auto completions. * May be {@code null}. */ public void setComboBox(final @CheckForNull JComboBox<E> comboBox) { changeComboBox(getComboBox(), comboBox, true); }
private void updateEditor(final ComboBoxEditor cbe, final @CheckForNull Object item) { if (lock()) return; try { cbe.setItem(item); if (!(item instanceof String)) return; final JComboBox<E> cb = getComboBox(); final JTextComponent tc = (JTextComponent) cbe.getEditorComponent(); assert cb.isShowing() || !tc.isFocusOwner(); if (!tc.isFocusOwner() /* || !cb.isShowing() */) return; // Compensate for an issue with some look and feels // which select the entire tc if an item is changed. // This is inconvenient for auto completion because the // next typed character would replace the entire tc... final Caret caret = tc.getCaret(); caret.setDot(((String) item).length()); } finally { unlock(); } }
private void documentUpdated() { if (lock()) return; try { final JComboBox<E> cb = getComboBox(); final ComboBoxEditor cbe = cb.getEditor(); final JTextComponent tc = (JTextComponent) cbe.getEditorComponent(); assert cb.isShowing() || !tc.isFocusOwner(); if (!tc.isFocusOwner() /* || !cb.isShowing() */) return; //cb.setPopupVisible(update(tc.getText())); // doesn't work: adjusts popup size! cb.setPopupVisible(false); if (update(tc.getText())) cb.setPopupVisible(true); } finally { unlock(); } }