title: Has anyone succeeded in autocomplete ComboBox for list cell?
body: <p>As standalone element, <a href="https://stackoverflow.com/questions/19924852/autocomplete-combobox-in-javafx">this</a> solution works fine.</p>
  
  <p>But in custom ListCell (mirrored from ComboBoxListCell sources), it gives sometimes:</p>
  
  <pre><code>Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
  at com.sun.javafx.scene.control.skin.ComboBoxPopupControl.positionAndShowPopup(ComboBoxPopupControl.java:100)
  at com.sun.javafx.scene.control.skin.ComboBoxPopupControl.show(ComboBoxPopupControl.java:74)
  at com.sun.javafx.scene.control.skin.ComboBoxBaseSkin.handleControlPropertyChanged(ComboBoxBaseSkin.java:115)
  at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin.handleControlPropertyChanged(ComboBoxListViewSkin.java:245)
  at com.sun.javafx.scene.control.skin.BehaviorSkinBase$2.call(BehaviorSkinBase.java:189)
  at com.sun.javafx.scene.control.skin.BehaviorSkinBase$2.call(BehaviorSkinBase.java:187)
  at com.sun.javafx.scene.control.MultiplePropertyChangeListenerHandler$1.changed(MultiplePropertyChangeListenerHandler.java:55)
  at javafx.beans.value.WeakChangeListener.changed(WeakChangeListener.java:89)
  at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:176)
  at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
  at javafx.beans.property.ReadOnlyBooleanWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyBooleanWrapper.java:178)
  at javafx.beans.property.ReadOnlyBooleanWrapper$ReadOnlyPropertyImpl.access$100(ReadOnlyBooleanWrapper.java:148)
  at javafx.beans.property.ReadOnlyBooleanWrapper.fireValueChangedEvent(ReadOnlyBooleanWrapper.java:144)
  at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:110)
  at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:143)
  at javafx.scene.control.ComboBoxBase.setShowing(ComboBoxBase.java:202)
  at javafx.scene.control.ComboBoxBase.show(ComboBoxBase.java:407)
  </code></pre>
  
  <p>Seems like show() method for ComboBox can produce NPE inside JavaFX code.</p>
  
  <p>Custom ComboBoxListCell differs only in startEdit():</p>
  
  <pre><code>@Override public void startEdit() {
      if (! isEditable() || ! getListView().isEditable()) {
          return;
      }
  
      if (comboBox == null) {
          comboBox = createComboBox(this, items, converterProperty());
  
          //The only special string
          handler = new AutoCompleteComboBoxListener&lt;&gt;(comboBox);
  
          comboBox.editableProperty().bind(comboBoxEditableProperty()); 
      }
  
      comboBox.getSelectionModel().select(getItem());
  
      super.startEdit();
  
      if (isEditing()) {
          setText(null);
          setGraphic(comboBox);
      }
  }
  </code></pre>
  
  <p>Code of AutoCompleteComboBoxListener that gives NPE:</p>
  
  <pre><code>@Override
  public void handle(KeyEvent event) {
  
      if(event.getCode() == KeyCode.UP) {
          caretPos = -1;
          moveCaret(comboBox.getEditor().getText().length());
          return;
      } else if(event.getCode() == KeyCode.DOWN) {
          if(!comboBox.isShowing()) {
              comboBox.show();
          }
          caretPos = -1;
          moveCaret(comboBox.getEditor().getText().length());
          return;
      } else if(event.getCode() == KeyCode.BACK_SPACE) {
          moveCaretToPos = true;
          caretPos = comboBox.getEditor().getCaretPosition();
      } else if(event.getCode() == KeyCode.DELETE) {
          moveCaretToPos = true;
          caretPos = comboBox.getEditor().getCaretPosition();
      }
  
      if (event.getCode() == KeyCode.RIGHT || event.getCode() == KeyCode.LEFT
              || event.isControlDown() || event.getCode() == KeyCode.HOME
              || event.getCode() == KeyCode.END || event.getCode() == KeyCode.TAB) {
          return;
      }
  
      ObservableList list = FXCollections.observableArrayList();
      for (int i=0; i&lt;data.size(); i++) {
          if(data.get(i).toString().toLowerCase().startsWith(
              AutoCompleteComboBoxListener.this.comboBox
              .getEditor().getText().toLowerCase())) {
              list.add(data.get(i));
          }
      }
      String t = comboBox.getEditor().getText();
  
      comboBox.setItems(list);
      comboBox.getEditor().setText(t);
      if(!moveCaretToPos) {
          caretPos = -1;
      }
      moveCaret(t.length());
      if(!list.isEmpty()) {
  
          //This gives NPE inside JavaFX API
          comboBox.show();
      }
  }
  </code></pre>