javafxtreetableview

JavaFX8 treeTableView customize collapse root item


How can I customize the collapse appearance of a tree root item? By customizing I mean setting an image and center that little triangle(/new image) inside its cell.

Thanks in advance.


Solution

  • Have a look at the default stylesheet, modena.css, which you can extract from the jfxrt.jar file in jre/lib/ext, or find online. The graphic is defined as a path there:

    .tree-cell > .tree-disclosure-node,
    .tree-table-row-cell > .tree-disclosure-node {
        -fx-padding: 4 6 4 8;
        -fx-background-color: transparent;
    }
    .tree-cell > .tree-disclosure-node > .arrow,
    .tree-table-row-cell > .tree-disclosure-node > .arrow {
        -fx-background-color: -fx-text-background-color;
        -fx-padding: 0.333333em 0.229em 0.333333em 0.229em; /* 4 */
        -fx-shape: "M 0 -3.5 L 4 0 L 0 3.5 z";
    }
    .tree-cell:expanded > .tree-disclosure-node > .arrow,
    .tree-table-row-cell:expanded > .tree-disclosure-node > .arrow {
        -fx-rotate: 90;
    }
    

    You can override these rules in your own css. The arrow referred to in the css is a Region, so you could define a -fx-background-image if you wanted.