Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8187314

All Cells: must show backing data always



    • b16


      Sync between visual content and backing data is broken, if the edited value is not written back into the item. The example below simply uses read-only data (effect is the same if a custom handler rejects the edit)

      To reproduce, run the example, edit a value, commit
      - expected: cell shows old value
      - actual: cell shows edited value

      To verify the mismatch, click onto the button to see that the backing data is the old. Decrease window size until the edited row is not visible, then increasse again to see that the correct old value appears again.

      The example:

      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TablePosition;
      import javafx.scene.control.TableView;
      import javafx.scene.control.cell.PropertyValueFactory;
      import javafx.scene.control.cell.TextFieldTableCell;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

       * TableViewCell: representation may be incorrect after commitEdit
      public class TableViewEditNotWritable extends Application {

          TablePosition<Dummy, String> editPosition;
          private Object editValue;
          public void start(Stage primaryStage) {
              TableView<Dummy> table = new TableView<>(Dummy.dummies());

              TableColumn<Dummy, String> first = new TableColumn<>("Text");
              first.setCellValueFactory(new PropertyValueFactory<>("dummy"));

              first.setOnEditStart(t -> editPosition = t.getTablePosition());
              first.addEventHandler(first.editCommitEvent(), t -> {
                  editValue = t.getNewValue();
                  System.out.println("doing nothing");


              Button button = new Button("Check value");
              button.setOnAction(e -> {
                  if (editPosition == null) return;
                  String value = editPosition.getTableColumn().getCellObservableValue(editPosition.getRow()).getValue();
                          "value in edited cell must represent backing data: " + value + " not the edited " + editValue);
              BorderPane root = new BorderPane(table);
              Scene scene = new Scene(root, 300, 250);

              primaryStage.setTitle("Hello World!");

          public static void main(String[] args) {
          public static class Dummy {
              private String dummy;
              public Dummy(String dummy) {
                  this.dummy = dummy;
              public String getDummy() {
                  return dummy;
              public static ObservableList<Dummy> dummies() {
                  return FXCollections.observableArrayList(
                          new Dummy("1"), new Dummy("2"), new Dummy("3")


        Issue Links



              mhanl Marius Hanl
              fastegal Jeanette Winzenburg
              0 Vote for this issue
              4 Start watching this issue