sbool AutoComboBox3_handleTab = true; sclass AutoComboBox3 extends JComboBox { F1> entryMaker; // called (serially) in non-AWT thread ReliableSingleThread rst = new(r { update2() }); S textBehindModel; *() { this(null); } *(F1> *entryMaker) { setSelectedIndex(-1); setEditable(true); JTextField text = cast this.getEditor().getEditorComponent(); text.setFocusable(true); text.addKeyListener(new KeyAdapter { public void /*keyPressed*/keyReleased(KeyEvent key) { if (key.getKeyCode() == KeyEvent.VK_ENTER) ret; if (key.getKeyCode() == KeyEvent.VK_ESCAPE) { hidePopup(); ret; } if (AutoComboBox3_handleTab && key.getKeyCode() == KeyEvent.VK_TAB /*&& key.getModifiers() == 0*/) { //_print("Have tab event (modifiers=" + key.getModifiers() + ")"); if (key.getModifiers() == 0 && isPopupVisible()) { setSelectedIndex(0); // accept item hidePopup(); } else // standard tab behavior swing_standardTabBehavior(key); ret; } JTextField tf = cast getEditor().getEditorComponent(); if (tf.getCaretPosition() != l(tf.getText())) ret; update(); } }); if (AutoComboBox3_handleTab) text.setFocusTraversalKeysEnabled(false); } Collection getSuggestions(S text) { ret callF(entryMaker, text); } JTextField textField() { ret (JTextField) getEditor().getEditorComponent(); } void update { if (neq(getText(textField()), textBehindModel)) rst.trigger(); } bool setTextBehindModel(fS text) { ret swing(func -> Bool { if (eq(text, textBehindModel)) false; textBehindModel = text; true; }); } void update2 { fS text = getText(textField()); if (!setTextBehindModel(text)) ret; try { final Vector list = new Vector(getSuggestions(text)); swing { if (nempty(list)) { S currentText = getText(textField()); setModel(new DefaultComboBoxModel(list)); setTextBehindModel(text); setSelectedIndex(-1); textField().setText(currentText); showPopup(); } else hidePopup(); } } catch print e { setTextBehindModel(null); } } }