TableView Editing Cell acts wierd
<p>I am building sort of a journal that will enable my users to collect specific data i.e, member no, and quantity for each member. Name of the member is supposed to be displayed once m/no is correct and user presses tab, which will make quantity start editing.</p>

<p>I found <a href="https://gist.github.com/abhinayagarwal/9383881" rel="nofollow">this</a> example and use it as a starting point.</p>

<p>I will post my work as SSCCE, but so that you know the little i have achieved is buggy. When i key first record</p>

<pre><code>    public class CollectionTVEdit extends Application{
        private TableView&lt;Collection&gt; table = new    TableView&lt;Collection&gt;();
        private ObservableList&lt;Collection&gt; collectionList = FXCollections.&lt;Collection&gt;observableArrayList();
        ListProperty&lt;Collection&gt; collectionListProperty = new SimpleListProperty&lt;&gt;();

        public static void main(String[] args) {
            launch(args);
        }

        @Override
       public void start(Stage primaryStage) throws Exception {
            primaryStage.setTitle("Table View Sample");
            primaryStage.setWidth(450);
            primaryStage.setHeight(550);

           final Label label = new Label("Address Book");
           label.setFont(new Font("Arial", 20));

           table.setEditable(true);
           Callback&lt;TableColumn, TableCell&gt; cellFactory = new Callback&lt;TableColumn, TableCell&gt;() {
            public TableCell call(TableColumn p) {
                    return new EditingCell();
            }
    };
    Callback&lt;TableColumn, TableCell&gt; floatCellFactory = new Callback&lt;TableColumn, TableCell&gt;() {
        public TableCell call(TableColumn p) {
                return new FloatEditingCell();
        }
    };

    TableColumn colMNO = new TableColumn("M/NO");
    colMNO.setMinWidth(100);
    colMNO.setCellValueFactory(new PropertyValueFactory("mno"));
    colMNO.setCellFactory(cellFactory);
    colMNO.setOnEditCommit(new EventHandler&lt;CellEditEvent&lt;Collection, String&gt;&gt;() {
        @Override
        public void handle(CellEditEvent&lt;Collection, String&gt; t) {
            ((Collection) t.getTableView().getItems()
                            .get(t.getTablePosition().getRow()))
                            .setMno(t.getNewValue());
        }
    });

    TableColumn colName = new TableColumn("Name");
    colName.setMinWidth(100);
    colName.setCellValueFactory(new PropertyValueFactory("name"));
    colName.setEditable(false);

    TableColumn colQuantity = new TableColumn("Quantity");
    colQuantity.setMinWidth(100);
    colQuantity.setCellValueFactory(new PropertyValueFactory("quantity"));
    colQuantity.setCellFactory(floatCellFactory);
    colQuantity.setOnEditCommit(new EventHandler&lt;CellEditEvent&lt;Collection, Float&gt;&gt;() {
        @Override
        public void handle(CellEditEvent&lt;Collection, Float&gt; t) {
            ((Collection) t.getTableView().getItems()
                            .get(t.getTablePosition().getRow()))
                            .setQuantity(t.getNewValue());
        }
    });

    collectionListProperty.set(collectionList);
    table.itemsProperty().bindBidirectional(collectionListProperty);
    table.getColumns().addAll(colMNO, colName, colQuantity);
    collectionList.add(new Collection());
    collectionList.add(new Collection());

    Scene scene = new Scene(new BorderPane(table), 880, 600);
    primaryStage.setScene(scene);
    primaryStage.show();
}


class FloatEditingCell extends TableCell&lt;Collection, Float&gt; {

    private TextField textField;

    public FloatEditingCell() {
    }

    @Override
    public void startEdit() {
        if (!isEmpty()) {
            super.startEdit();
            if (textField == null) {
                createTextField();
            }

            setGraphic(textField);
            setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
            // textField.selectAll();
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    textField.requestFocus();
                    textField.selectAll();
                }
            });
        }
    }

    @Override
    public void cancelEdit() {
        super.cancelEdit();

        setText(""+(Float) getItem());
        setGraphic(null);
    }

    @Override
    public void updateItem(Float item, boolean empty) {
        super.updateItem(item, empty);

        if (empty) {
            setText(null);
            setGraphic(null);
        } else {
            if (isEditing()) {
                if (textField != null) {
                    textField.setText(getString());
                }
                setGraphic(textField);
                setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
            } else {
           //                                    table.getColumns().get(0).setVisible(false);//////////////my new line
           //                                    table.getColumns().get(0).setVisible(true);///////////////my new line
                setText(getString());
                setContentDisplay(ContentDisplay.TEXT_ONLY);
            }
        }
    }

    private void createTextField() {
        textField = new TextField(getString());
        textField.setMinWidth(this.getWidth() - this.getGraphicTextGap()
                * 2);

        textField.focusedProperty().addListener(
                new ChangeListener&lt;Boolean&gt;() {
                    @Override
                    public void changed(
                            ObservableValue&lt;? extends Boolean&gt; arg0,
                            Boolean arg1, Boolean arg2) {
                        if (!arg2) {
                            commitEdit(Float.parseFloat(textField.getText()));
                        }
                    }
                });

        textField.setOnKeyPressed(new EventHandler&lt;KeyEvent&gt;() {
            @Override
            public void handle(KeyEvent t) {
                if (t.getCode() == KeyCode.ENTER) {
                    commitEdit(Float.parseFloat(textField.getText()));
                } else if (t.getCode() == KeyCode.ESCAPE) {
                    cancelEdit();
                } else if (t.getCode() == KeyCode.TAB) {
                    commitEdit(Float.parseFloat(textField.getText()));
                    TableColumn nextColumn = getNextColumn(!t.isShiftDown());
                if (nextColumn != null) {
                    getTableView().edit(getTableRow().getIndex(),
                            nextColumn);
                }

                }
            }

        });
    }

    private String getString() {
        return getItem() == null ? "" : getItem().toString();
    }

    private TableColumn&lt;Collection, ?&gt; getNextColumn(boolean forward) {
        List&lt;TableColumn&lt;Collection, ?&gt;&gt; columns = new ArrayList&lt;&gt;();
        for (TableColumn&lt;Collection, ?&gt; column : getTableView().getColumns()) {
            columns.addAll(getLeaves(column));
        }
        // There is no other column that supports editing.
        if (columns.size() &lt; 2) {
            return null;
        }
        int currentIndex = columns.indexOf(getTableColumn());
        int nextIndex = currentIndex;
        if (forward) {
            nextIndex++;
            if (nextIndex &gt; columns.size() - 1) {
                nextIndex = 0;
                                    table.getItems().add(new Collection());
            }
        } else {
            nextIndex--;
            if (nextIndex &lt; 0) {
                nextIndex = columns.size() - 1;
            }
        }
        return columns.get(nextIndex);
    }

    private List&lt;TableColumn&lt;Collection, ?&gt;&gt; getLeaves(
            TableColumn&lt;Collection, ?&gt; root) {
        List&lt;TableColumn&lt;Collection, ?&gt;&gt; columns = new ArrayList&lt;&gt;();
        if (root.getColumns().isEmpty()) {
            // We only want the leaves that are editable.
            if (root.isEditable()) {
                columns.add(root);
            }
            return columns;
        } else {
            for (TableColumn&lt;Collection, ?&gt; column : root.getColumns()) {
                columns.addAll(getLeaves(column));
            }
            return columns;
        }
    }
}

class EditingCell extends TableCell&lt;Collection, String&gt; {

    private TextField textField;

    public EditingCell() {
    }

    @Override
    public void startEdit() {
        if (!isEmpty()) {
            super.startEdit();
            if (textField == null) {
                createTextField();
            }

            setGraphic(textField);
            setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
            // textField.selectAll();
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    textField.requestFocus();
                    textField.selectAll();
                }
            });
        }
    }

    @Override
    public void cancelEdit() {
        super.cancelEdit();

        setText((String) getItem());
        setGraphic(null);
    }

    @Override
    public void updateItem(String item, boolean empty) {
        super.updateItem(item, empty);

        if (empty) {
            setText(null);
            setGraphic(null);
        } else {
            if (isEditing()) {
                if (textField != null) {
                    textField.setText(getString());
                }
                setGraphic(textField);
                setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
            } else {
                setText(getString());
                setContentDisplay(ContentDisplay.TEXT_ONLY);
            }
        }
    }

    private void createTextField() {
        textField = new TextField(getString());
        textField.setMinWidth(this.getWidth() - this.getGraphicTextGap()
                * 2);

        textField.focusedProperty().addListener(
                new ChangeListener&lt;Boolean&gt;() {
                    @Override
                    public void changed(
                            ObservableValue&lt;? extends Boolean&gt; arg0,
                            Boolean arg1, Boolean arg2) {
                        if (!arg2) {
                            commitEdit(textField.getText());
                        }
                    }
                });

        textField.setOnKeyPressed(new EventHandler&lt;KeyEvent&gt;() {
            @Override
            public void handle(KeyEvent t) {
                if (t.getCode() == KeyCode.ENTER) {
                    commitEdit(textField.getText());
                } else if (t.getCode() == KeyCode.ESCAPE) {
                    cancelEdit();
                } else if (t.getCode() == KeyCode.TAB) {
                    commitEdit(textField.getText());
                    TableColumn nextColumn = getNextColumn(!t.isShiftDown());
                if (nextColumn != null) {
                    getTableView().edit(getTableRow().getIndex(),
                            nextColumn);
                }

                }
            }

        });
    }

    private String getString() {
        return getItem() == null ? "" : getItem().toString();
    }

    private TableColumn&lt;Collection, ?&gt; getNextColumn(boolean forward) {
        List&lt;TableColumn&lt;Collection, ?&gt;&gt; columns = new ArrayList&lt;&gt;();
        for (TableColumn&lt;Collection, ?&gt; column : getTableView().getColumns()) {
            columns.addAll(getLeaves(column));
        }
        // There is no other column that supports editing.
        if (columns.size() &lt; 2) {
            return null;
        }
        int currentIndex = columns.indexOf(getTableColumn());
        int nextIndex = currentIndex;
        if (forward) {
            nextIndex++;
            if (nextIndex &gt; columns.size() - 1) {
                nextIndex = 0;
                                    table.getItems().add(new Collection());
            }
        } else {
            nextIndex--;
            if (nextIndex &lt; 0) {
                nextIndex = columns.size() - 1;
            }
        }
        return columns.get(nextIndex);
    }

    private List&lt;TableColumn&lt;Collection, ?&gt;&gt; getLeaves(
            TableColumn&lt;Collection, ?&gt; root) {
        List&lt;TableColumn&lt;Collection, ?&gt;&gt; columns = new ArrayList&lt;&gt;();
        if (root.getColumns().isEmpty()) {
            // We only want the leaves that are editable.
            if (root.isEditable()) {
                columns.add(root);
            }
            return columns;
        } else {
            for (TableColumn&lt;Collection, ?&gt; column : root.getColumns()) {
                columns.addAll(getLeaves(column));
            }
            return columns;
        }
    }
}

public class Collection {
    private int id;
    private String mno;
    private String name;
    private float quantity;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getMno() {
        return mno;
    }

    public void setMno(String mno) {
        this.mno = mno;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public float getQuantity() {
        return quantity;
    }

    public void setQuantity(float quantity) {
        this.quantity = quantity;
    }
}

}
</code></pre>

<p>What i want to achieve is user to be able to insert data in a table which is binded to a list. Later maybe on button click i pick the list and persist to db. Problem right now is table behaves strangely. Does not hold data, sometime insert data is shown in a different cell</p>