diff --git a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeViewSkin.java b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeViewSkin.java --- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeViewSkin.java +++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeViewSkin.java @@ -196,6 +196,12 @@ } private void updateItemCount() { + int newCount = getItemCount(); + + // RT-20090: refer to TreeView for further details on why -1 is treated + // like this. + if (newCount == -1) return; + // we're about to recreate all cells - but before that we detach them // from the TreeView, such that their listeners can be uninstalled. // If we don't do this, we start to get multiple events firing when @@ -204,19 +210,11 @@ ((TreeCell)flow.cells.get(i)).updateTreeView(null); } - int oldCount = flow.getCellCount(); - int newCount = getItemCount(); - // if this is not called even when the count is the same, we get a // memory leak in VirtualFlow.sheet.children. This can probably be // optimised in the future when time permits. flow.setCellCount(newCount); - - if (newCount != oldCount) { - flow.recreateCells(); - } else { - flow.reconfigureCells(); - } + flow.recreateCells(); } @Override public TreeCell createCell() { diff --git a/javafx-ui-controls/src/javafx/scene/control/TreeView.java b/javafx-ui-controls/src/javafx/scene/control/TreeView.java --- a/javafx-ui-controls/src/javafx/scene/control/TreeView.java +++ b/javafx-ui-controls/src/javafx/scene/control/TreeView.java @@ -865,6 +865,14 @@ } private void updateTreeItemCount() { + treeItemCountDirty = false; + + // RT-20090 We set the TreeItemCount to -1 temporarily to indicate that + // the value is about to change, and to allow for events to fire even + // when the overall item count remains the same (yet the actual children + // have changed). We also have added code to the skin to ensure + setTreeItemCount(-1); + if (getRoot() == null) { setTreeItemCount(0); } else if (! getRoot().isExpanded()) { @@ -875,7 +883,6 @@ setTreeItemCount(count); } - treeItemCountDirty = false; } private TreeItem getItem(TreeItem parent, int itemIndex) {