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

ListCell Item not updated when ListView items change

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • fx2.0
    • fx2.0
    • javafx
    • None

      It appears that we do not currently bind the ListCell to the ListView.items, such that when the items changes the cells are updated. For example, the following code has a ListCell who's range is beyond that of the ListView.items. The items is updated however, and it should then be in range such that the cell.getItem() method should return an actual item, but it doesn't.

          @Before public void setup() {
              cell = new ListCell<String>();
              model = FXCollections.observableArrayList("Apples", "Oranges", "Pears");
              list = new ListView<String>(model);
          }

          @Test public void itemIsUpdatedWhenItWasOutOfRangeButUpdatesToListViewItemsMakesItInRange() {
              cell.updateIndex(4);
              cell.updateListView(list);
              model.addAll("Pumpkin", "Lemon");
              assertSame(model.get(4), cell.getItem());
          }


      Now in the real code, the ListViewSkin is probably listening to the TableView and managing this update, for performance reasons (one listener vs. thousands of listeners). However this creates something of an odd situation where the API and implementation of ListCell, in isolation of an "intelligent" skin, doesn't work. Now, it does keep track of the selection model and focus model, leading one to think it ought to also keep track of the ListView's items.

            rbair Richard Bair (Inactive)
            rbair Richard Bair (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: