title: How to implement correct doubleclick-to-edit in TableView
body: <p><strong>Problem</strong> </p>
  
  <p>The TableView seems to go into edit mode as soon as you click on an already selected cell. This is unwanted and inconsistent behavior, because the selection changes if you click outside of the current selection. It doesn't change when you click inside the current selection. </p>
  
  <p>If anything, a real double click should be required to go into edit mode, at least when you work on a desktop.</p>
  
  <p><em>Reproduction:</em></p>
  
  <p>Create a TableView with this selection mode:</p>
  
  <pre><code>// cell selection mode instead of row selection
  table.getSelectionModel().setCellSelectionEnabled(true);
  
  // allow selection of multiple cells
  table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
  </code></pre>
  
  <p>Now select multiple cells (via shift keypress). Then click on a single cell of the currently selected cells.</p>
  
  <p>The current behavior:</p>
  
  <ul>
  <li>the table goes into edit mode</li>
  </ul>
  
  <p><strong>Question</strong></p>
  
  <p>The requested behavior:</p>
  
  <ul>
  <li>only the selection should change, i. e. the single cell should be selected; edit mode should only happen on a double-click</li>
  </ul>
  
  <p>How can you achieve this?</p>
  
  <p><strong>Code</strong></p>
  
  <p>Here's a full example. I took the code from the Oracle samples website, added the above lines and pre-selected all cells. When you click on a single cell after program start, the table goes directly into edit mode:</p>
  
  <pre><code>public class TableViewSample extends Application {
  
      private TableView&lt;Person&gt; table = new TableView&lt;Person&gt;();
      private final ObservableList&lt;Person&gt; data =
              FXCollections.observableArrayList(
              new Person("Jacob", "Smith", "jacob.smith@example.com"),
              new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
              new Person("Ethan", "Williams", "ethan.williams@example.com"),
              new Person("Emma", "Jones", "emma.jones@example.com"),
              new Person("Michael", "Brown", "michael.brown@example.com"));
      final HBox hb = new HBox();
  
      public static void main(String[] args) {
          launch(args);
      }
  
      @Override
      public void start(Stage stage) {
          Scene scene = new Scene(new Group());
          stage.setTitle("Table View Sample");
          stage.setWidth(450);
          stage.setHeight(550);
  
          final Label label = new Label("Address Book");
          label.setFont(new Font("Arial", 20));
  
          table.setEditable(true);
  
          TableColumn firstNameCol = new TableColumn("First Name");
          firstNameCol.setMinWidth(100);
          firstNameCol.setCellValueFactory(
              new PropertyValueFactory&lt;Person, String&gt;("firstName"));
          firstNameCol.setCellFactory(TextFieldTableCell.forTableColumn());
          firstNameCol.setOnEditCommit(
              new EventHandler&lt;CellEditEvent&lt;Person, String&gt;&gt;() {
                  @Override
                  public void handle(CellEditEvent&lt;Person, String&gt; t) {
                      ((Person) t.getTableView().getItems().get(
                              t.getTablePosition().getRow())
                              ).setFirstName(t.getNewValue());
                  }
              }
          );
  
  
          TableColumn lastNameCol = new TableColumn("Last Name");
          lastNameCol.setMinWidth(100);
          lastNameCol.setCellValueFactory(
              new PropertyValueFactory&lt;Person, String&gt;("lastName"));
          lastNameCol.setCellFactory(TextFieldTableCell.forTableColumn());
          lastNameCol.setOnEditCommit(
              new EventHandler&lt;CellEditEvent&lt;Person, String&gt;&gt;() {
                  @Override
                  public void handle(CellEditEvent&lt;Person, String&gt; t) {
                      ((Person) t.getTableView().getItems().get(
                          t.getTablePosition().getRow())
                          ).setLastName(t.getNewValue());
                  }
              }
          );
  
          TableColumn emailCol = new TableColumn("Email");
          emailCol.setMinWidth(200);
          emailCol.setCellValueFactory(
              new PropertyValueFactory&lt;Person, String&gt;("email"));
          emailCol.setCellFactory(TextFieldTableCell.forTableColumn());
          emailCol.setOnEditCommit(
              new EventHandler&lt;CellEditEvent&lt;Person, String&gt;&gt;() {
                  @Override
                  public void handle(CellEditEvent&lt;Person, String&gt; t) {
                      ((Person) t.getTableView().getItems().get(
                          t.getTablePosition().getRow())
                          ).setEmail(t.getNewValue());
                  }
              }
          );
  
          table.setItems(data);
          table.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
  
          final TextField addFirstName = new TextField();
          addFirstName.setPromptText("First Name");
          addFirstName.setMaxWidth(firstNameCol.getPrefWidth());
          final TextField addLastName = new TextField();
          addLastName.setMaxWidth(lastNameCol.getPrefWidth());
          addLastName.setPromptText("Last Name");
          final TextField addEmail = new TextField();
          addEmail.setMaxWidth(emailCol.getPrefWidth());
          addEmail.setPromptText("Email");
  
          final Button addButton = new Button("Add");
          addButton.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
              @Override
              public void handle(ActionEvent e) {
                  data.add(new Person(
                          addFirstName.getText(),
                          addLastName.getText(),
                          addEmail.getText()));
                  addFirstName.clear();
                  addLastName.clear();
                  addEmail.clear();
              }
          });
  
          hb.getChildren().addAll(addFirstName, addLastName, addEmail, addButton);
          hb.setSpacing(3);
  
          final VBox vbox = new VBox();
          vbox.setSpacing(5);
          vbox.setPadding(new Insets(10, 0, 0, 10));
          vbox.getChildren().addAll(label, table, hb);
  
          ((Group) scene.getRoot()).getChildren().addAll(vbox);
  
          stage.setScene(scene);
          stage.show();
  
          // cell selection mode instead of row selection
          table.getSelectionModel().setCellSelectionEnabled(true);
  
          // allow selection of multiple cells
          table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
  
          // select all for demo purposes
          table.getSelectionModel().selectAll();
      }
  
      public static class Person {
  
          private final SimpleStringProperty firstName;
          private final SimpleStringProperty lastName;
          private final SimpleStringProperty email;
  
          private Person(String fName, String lName, String email) {
              this.firstName = new SimpleStringProperty(fName);
              this.lastName = new SimpleStringProperty(lName);
              this.email = new SimpleStringProperty(email);
          }
  
          public String getFirstName() {
              return firstName.get();
          }
  
          public void setFirstName(String fName) {
              firstName.set(fName);
          }
  
          public String getLastName() {
              return lastName.get();
          }
  
          public void setLastName(String fName) {
              lastName.set(fName);
          }
  
          public String getEmail() {
              return email.get();
          }
  
          public void setEmail(String fName) {
              email.set(fName);
          }
      }
  }
  </code></pre>