JDK-8125030 : ListCell.updateItem has strage invocation in list view
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 7u6
  • Priority: P3
  • Status: Resolved
  • Resolution: Won't Fix
  • Submitted: 2012-08-18
  • Updated: 2015-06-17
  • Resolved: 2013-08-27
Related Reports
Blocks :  
Description
Run code to reproduce. There are a lot of unexpected invocations

 @Override
    public void start(Stage primaryStage) {
        
        StackPane root = new StackPane();
        ListView list =  new ListView();
        list.setCellFactory(new Callback<ListView, ListCell>() {
            @Override
            public ListCell call(final ListView param) {
                return new ListCell() {

                    @Override
                    protected void updateItem(Object item, boolean empty) {
                        super.updateItem(item, empty);
                        System.out.println("Update item invoked " + getIndex());
                    }
                };
            }
        });
        root.getChildren().addAll(list);
        
        Scene scene = new Scene(root, 300, 250);
        
        primaryStage.setScene(scene);
        primaryStage.show();
    }


////output
Update item invoked -1
Update item invoked 0
Update item invoked 0
Update item invoked -1
Update item invoked -1
Update item invoked -1
Update item invoked 0
Update item invoked 0
Update item invoked -1
Update item invoked 1
Update item invoked 1
Update item invoked -1
Update item invoked 2
Update item invoked 2
Update item invoked -1
Update item invoked 3
Update item invoked 3
Update item invoked -1
Update item invoked 4
Update item invoked 4
Update item invoked -1
Update item invoked 5
Update item invoked 5
Update item invoked -1
Update item invoked 6
Update item invoked 6
Update item invoked -1
Update item invoked 7
Update item invoked 7
Update item invoked -1
Update item invoked 8
Update item invoked 8
Update item invoked -1
Update item invoked 9
Update item invoked 9
Update item invoked -1
Update item invoked 10
Update item invoked 10
Comments
Due to fix was backed out
04-06-2013

Unfortunately I have backed out this fix as it caused RT-30398.
30-05-2013

I slightly tweaked the test application (copied below), and after a few tweaks to the cell code I now see the following output: Update item invoked 0 Update item invoked -1 Update item invoked 0 Update item invoked 1 Update item invoked 2 Update item invoked 3 Update item invoked 4 Update item invoked 5 Update item invoked 6 Update item invoked 7 Update item invoked 8 Update item invoked 9 I would therefore say that this issue is now resolved. The updated test code is as below: import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.layout.StackPane; import javafx.stage.Stage; import javafx.util.Callback; public class RT24358 extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { StackPane root = new StackPane(); ListView<String> list = new ListView<String>(); list.getItems().addAll("Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10"); list.setCellFactory(new Callback<ListView<String>, ListCell<String>>() { @Override public ListCell<String> call(final ListView<String> param) { return new ListCell<String>() { @Override protected void updateItem(String item, boolean empty) { super.updateItem(item, empty); setText(item == null ? "null" : item); System.out.println("Update item invoked " + getIndex()); } }; } }); root.getChildren().addAll(list); Scene scene = new Scene(root, 300, 250); primaryStage.setScene(scene); primaryStage.show(); } }
01-05-2013

All my custom ListCells behave that way. A simple sout in the cell's constructor shows that each time 1 cell is added, the constructor is called around 16 times (this leads to performance issues).
12-12-2012