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

Layout pass of TreeView can result in unneccessary recreation of TreeCells

    Details

      Description

      I was asked to file a separate issue for this in this forum post https://forums.oracle.com/forums/thread.jspa?threadID=2370471&tstart=0. It is somewhat related to issue RT-20616.

      What is happening is that in my program I use filters on my TreeView. Whenever the filter is changed, a new root is given to the TreeView with only the items that should be displayed when this filter is active (so much for the use case).

      Each time I set the root of the tree though about 30-40 new TreeCells are being created, despite the fact that the CellFactory was never changed after creation of the TreeView.

      Now, when I switch filter (this is like a row of tabs above the TreeView) a layout pass is triggered to update the active tab shown. The TreeView itself is not actually in a StackPane or anything, the tabs on top of it are just there for show (in other words, it is not a real tab pane). However, the layout pass determines that the TreeView must also be re-rendered (no surprise as the root was also changed when the filter changed) and this layout pass for some reason causes a listener to be triggered on the height-property of the TreeView (which is surprising as the height of the control certainly doesn't change).

      I've traced this happening in the VirtualFlow class, where there is a listener on the height property, here is a bit of decompiled code:

          super.heightProperty().addListener(new ChangeListener()
          {
            public void changed(ObservableValue<? extends Number> paramObservableValue, Number paramNumber1, Number paramNumber2)
            {
              if ((paramNumber1.doubleValue() == 0.0D) && (paramNumber2.doubleValue() > 0.0D))
                VirtualFlow.this.recreateCells();
            }
          });

      For some reason the "VirtualFlow.this.recreateCells()" gets triggered during the layout pass -- all cells get discarded, and new ones are created.

      I hope this is useful in tracing the problem -- I would think that cells could be re-used indefinitely until the CellFactory is changed, but perhaps there are other reasons why cells need to be recreated.

        Attachments

          Activity

            People

            • Assignee:
              jgiles Jonathan Giles
              Reporter:
              jhendrikx John Hendrikx
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: