title: javafx combobox editable autocomplete
body: <p>I have created a combo box which adds list of entries. I have made this combo box as editable and autocomplete. The issue is as follows </p>
  
  <p>1)I selected the Arial value from the dropdown using mouseclick. </p>
  
  <p>2)After that I typed black and from the result list I selected Arial Black using enter button.</p>
  
  <p>3)Then again I clicked on Arial value using mouseclick ,the Arial value gets selected but along with it the result List is shown again even though i selected the value. </p>
  
  <p>I want to hide the result list on click of mouse selection value. The result list is nothing but ComboBoxPopupControl. I tried using dispose method but it dint worked. Can anyone suggest the code on click of comboBox.setOnAction.</p>
  
  <p><a href="https://i.stack.imgur.com/d4JOq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d4JOq.png" alt="enter image description here"></a></p>
  
  <p>Here is the code</p>
  
  <pre><code>java.util.ArrayList;
  import java.util.List;
  
  import org.controlsfx.control.textfield.TextFields;
  
  import javafx.application.Application;
  import javafx.event.ActionEvent;
  import javafx.event.EventHandler;
  import javafx.event.EventType;
  import javafx.scene.Group;
  import javafx.scene.Scene;
  import javafx.scene.control.ComboBox;
  import javafx.scene.input.KeyCode;
  import javafx.scene.input.KeyEvent;
  import javafx.scene.input.MouseEvent;
  import javafx.stage.Stage;
  
  public class TestAutoTextSearch_bkp extends Application {
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          launch();
  
      }
  
      @Override
      public void start(Stage primaryStage) throws Exception {
          List&lt;String&gt; countries = new ArrayList&lt;&gt;();
          countries.add("Arial");
          countries.add("Arial Black");
          countries.add("Arial Narrow");
  
  
          ComboBox&lt;String&gt; comboBox = new ComboBox();
          comboBox.getItems().addAll(countries);
          ComboBox&lt;String&gt; comboBox1 = new ComboBox();
  
          comboBox.setEditable(true);
          comboBox.setMaxWidth(Double.MAX_VALUE);
  
  
  
  
  
  
          comboBox.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
              @Override
              public void handle(ActionEvent event) {
                  //Tried dispose method here but dint worked[![enter image description here][1]][1]
  
  
              }
          });
  
          comboBox.getEditor().setOnKeyPressed(new EventHandler&lt;KeyEvent&gt;() {
              @Override
              public void handle(KeyEvent ke) {
                   KeyCode kc = ke.getCode();
                  System.out.println("Inside Key Press");
                   if ((kc.isLetterKey())||kc.isArrowKey()||kc.equals(KeyCode.BACK_SPACE)) {
                        TextFields.bindAutoCompletion(comboBox.getEditor(), comboBox.getItems());
  
  
              }}
          });
  
  
  
  
  
  
  
  
          Group root = new Group();
          root.getChildren().add(comboBox);
  
          Scene scene = new Scene(root);
          primaryStage.setScene(scene);
          primaryStage.show();
  
          comboBox.setMinWidth(comboBox.getWidth());
          comboBox.setPrefWidth(comboBox.getWidth());
  
      }
  
  }
  </code></pre>