title: Javafx Listview Add and edit element
body: <p>i want to  add and edit directly an element to a listview :</p>
  
  <pre><code>/*
   * To change this license header, choose License Headers in Project Properties.
   * To change this template file, choose Tools | Templates
   * and open the template in the editor.
   */
  package javafx_test;
  
  import java.util.Observable;
  import javafx.application.Application;
  import javafx.collections.FXCollections;
  import javafx.collections.ObservableList;
  import javafx.event.ActionEvent;
  import javafx.event.EventHandler;
  import javafx.scene.Scene;
  import javafx.scene.control.Button;
  import javafx.scene.control.ListCell;
  import javafx.scene.control.ListView;
  import javafx.scene.control.cell.TextFieldListCell;
  import javafx.scene.layout.StackPane;
  import javafx.scene.layout.VBox;
  import javafx.stage.Stage;
  import javafx.util.Callback;
  import javafx.util.StringConverter;
  
  /**
   *
   * @author karim
   */
  public class Javafx_test extends Application {
  
      @Override
      public void start(Stage primaryStage) {
          ObservableList&lt;String&gt; items = FXCollections.observableArrayList("test1", "test2");
          ListView&lt;String&gt; list = new ListView&lt;&gt;(items);
  
          list.setEditable(true);
          list.setCellFactory(new Callback&lt;ListView&lt;String&gt;, ListCell&lt;String&gt;&gt;() {
  
              @Override
              public ListCell&lt;String&gt; call(ListView&lt;String&gt; param) {
                  return new TextFieldListCell&lt;&gt;(new StringConverter&lt;String&gt;() {
  
                      @Override
                      public String toString(String object) {
                          return object;
                      }
  
                      @Override
                      public String fromString(String string) {
                          return string;
                      }
                  });
              }
          });
  
          Button btn = new Button();
          btn.setText("Add String");
          btn.setOnAction((ActionEvent event) -&gt; {
              String c = new String("test");
              list.getItems().add(list.getItems().size(), c);
              list.scrollTo(c);
              list.edit(list.getItems().size() - 1);
          });
  
          VBox root = new VBox(list, btn);
  
          Scene scene = new Scene(root);
  
          primaryStage.setTitle("test!");
          primaryStage.setScene(scene);
          primaryStage.show();
      }
  
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args) {
          launch(args);
      }
  
  }
  </code></pre>
  
  <p>Everything seems correct but that not working, it like its try to modify the first item not the newly added item in the last index, i don't know why</p>