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

ListView doesn't update cells after null item removal

XMLWordPrintable

    • x86_64
    • generic

      A DESCRIPTION OF THE PROBLEM :
      This is very similar to RT-32621, a bug in TreeTableCell, fixed some time ago by introducing indexExceedsItemCount in updateItem(int).
      I believe that ListCell and TreeCell should be fixed at the same time. Sadly, they were not.

      Please compare
      https://hg.openjdk.java.net/openjfx/9/rt/file/tip/modules/javafx.controls/src/main/java/javafx/scene/control/TreeTableCell.java#l626
      with
      https://hg.openjdk.java.net/openjfx/9/rt/file/tip/modules/javafx.controls/src/main/java/javafx/scene/control/ListCell.java#l486
      and
      https://hg.openjdk.java.net/openjfx/9/rt/file/tip/modules/javafx.controls/src/main/java/javafx/scene/control/TreeCell.java#l531.

      Related bug (mentioned earlier):
      https://bugs.openjdk.java.net/browse/JDK-8115233
      Possibly related bug (null items + list view):
      https://bugs.openjdk.java.net/browse/JDK-8181907


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Add 2 items to the list, then remove 1. The 2nd item will be still editable.

      Setting custom cell factory (TextFieldListCell) is not essential to this bug, but it makes things easier to see. Please check ListView strange behavior without setting it too.



      ---------- BEGIN SOURCE ----------
      package sandbox;

      import javafx.application.Application;
      import javafx.beans.binding.Bindings;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ListView;
      import javafx.scene.control.cell.TextFieldListCell;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class Main extends Application {
      public static void main(String[] args) {
      launch(args);
      }

      @Override
      public void start(Stage primaryStage) throws Exception {
      ObservableList<String> items = FXCollections.observableArrayList();

      ListView<String> list = new ListView<>(items);

      // it's easier to see this bug when custom cell factory is used
      list.setCellFactory(TextFieldListCell.forListView());
      list.setEditable(true);

      Button minus = new Button("-");
      Button plus = new Button("+");
      minus.disableProperty().bind(Bindings.isEmpty(items));
      minus.setOnAction(e -> items.remove(items.size() - 1));
      plus.setOnAction(e -> items.add(null));

      VBox root = new VBox(new HBox(minus, plus), list);

      Scene scene = new Scene(root, 400, 300);
      primaryStage.setScene(scene);
      primaryStage.show();
      }
      }

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

            aghaisas Ajit Ghaisas
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: