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

[TreeView] DisclosureNode set to null, still takes up space

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8
    • Fix Version/s: tbd
    • Component/s: javafx
    • Environment:

      JavaFX 8b113

      Description

      No matter what I do (playing with -fx-indent, setting DisclosureNode to null, or an empty Rectangle), the default TreeCellSkin implementation will reserve 18 pixels for the disclosure node.

      This is despite the fact that the TreeCellSkin code determined that the node is not visible already:

              boolean disclosureVisible = disclosureNode != null && treeItem != null && ! treeItem.isLeaf();

      It will still calculate the disclosureWidth:

              final double defaultDisclosureWidth = maxDisclosureWidthMap.containsKey(tree) ?
                  maxDisclosureWidthMap.get(tree) : 18; // RT-19656: default width of default disclosure node
              double disclosureWidth = defaultDisclosureWidth;

      And then use it in its calculation of where to layout the label/graphic of the cell node:

              // determine starting point of the graphic or cell node, and the
              // remaining width available to them
              final int padding = treeItem != null && treeItem.getGraphic() == null ? 0 : 3;
              x += disclosureWidth + padding;
              w -= (leftMargin + disclosureWidth + padding);

              layoutLabelInArea(x, y, w, h);

      From what I can see, the disclosureVisible boolean is there as an indication of whether a disclosure node should be rendered or not but does not control whether space should be reserved for it or not. I think an additional check needs to be added that collapses the default 18 pixels to 0 pixels if disclosureNode == null.

      I think the code should be rewritten as:

          boolean disclosureVisible = treeItem != null && ! treeItem.isLeaf();

          final double defaultDisclosureWidth = disclosureNode == null ? 0 : maxDisclosureWidthMap.containsKey(tree) ?
              maxDisclosureWidthMap.get(tree) : 18; // RT-19656: default width of default disclosure node
          double disclosureWidth = defaultDisclosureWidth;

          if (disclosureVisible && disclosureNode != null) {

      This also makes clear that there is a slight logic error inside the if block, where disclosureNode is tested against null twice -- however since this was already taken into account in the disclosureVisible boolean, those checks are redundant.

      I'm also a bit worried about the 3 pixels of padding getting added when treeItem != null && treeItem.getGraphic() == null... when controlling the TreeCells precisely (especially when it is set to GRAPHIC_ONLY) I apparently still get 3 free pixels of padding.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              jhendrikx John Hendrikx
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Imported: