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

TableView selectedItems remove causes artifacts in bindContent

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Build:
      b04
    • Introduced In Version:
    • CPU:
      x86_64
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      java version "1.8.0_162"
      Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      I bind a list to the selected items of a TableView.
      If i select any element and remove this from the underlying list, the change is not reflected in the bound list, even if the selected items seems to be correct.

      I assume the problem is related to the selection handling in TableView.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Result with JDK 1.8.162
      Select first row:
      Bindings.bindContent changed { [P1] added at 0 }
      - P1
      TableView.selection changed { [P1] added at 0, }
      - P1

      Remove first element:
      TableView.selection changed { [] added at 0, }
      - P2
      Bindings.bindContent changed { [P2] added at 0 }
      - P2
      - P1 <- "P1" should not be in the list anymore
      TableView.selection changed { [P2] added at 0, }
      - P2


      Result of JDK 10.0.1
      Select first row:
      Bindings.bindContent changed { [P1] added at 0 }
      - P1
      TableView.selection changed { [P1] added at 0 }
      - P1

      Remove first element (P1):
      Bindings.bindContent changed { [P2] added at 0 }
      - P2
      - P1 <- "P1" should not be in the list anymore
      TableView.selection changed { [P2] added at 0 }
      - P2

      ---------- BEGIN SOURCE ----------
      ObservableList<String> selectedRows = FXCollections.observableArrayList();

      TableColumn<String, String> column = new TableColumn<>("Name");
      column.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue()));

      TableView<String> tableView = new TableView<>();
      tableView.getColumns().add(column);
      tableView.setItems(FXCollections.observableArrayList("P1", "P2"));

      Bindings.bindContent(selectedRows, tableView.getSelectionModel().getSelectedItems());

      tableView.getSelectionModel().getSelectedItems().addListener((ListChangeListener<? super String>) c -> {
      System.out.println("TableView.selection changed \t" + c);
      tableView.getSelectionModel().getSelectedItems().forEach(x->System.out.println("- " + x));
      });
      selectedRows.addListener((ListChangeListener<? super String>) c -> {
      System.out.println("Bindings.bindContent changed\t" + c);
      selectedRows.forEach(x->System.out.println("- " + x));
      });

      System.out.println("Select first row:");
      tableView.getSelectionModel().select(0);

      System.out.println("\nRemove first element (P1):");
      tableView.getItems().remove(0);

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Clearing the selection before removing any element works, but is not a good solution for production.

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: