1

I want to create a treetableview which can show for every tree item a sub tree with a row which contains custom nodes (in this case a button).

In the end i want to make it look like that.

In order to achieve that i probably need a custom row factory.

//set custom row factory
    treeTableView.setRowFactory(new Callback<TreeTableView<Struct>, TreeTableRow<Struct>>() {
        @Override
        public TreeTableRow<Struct> call(TreeTableView<Struct> param) {
            return new TreeTableRow<Struct>(){
                @Override
                protected void updateItem(Struct item, boolean empty) {
                    super.updateItem(item, empty);
                    //check if row has values
                    if (!empty) {
                        //override the row cell graphics if boolean is set
                        if (item.isCustomRow()) {
                            setGraphic(new StackPane(new Button("Button")));
                        }
                    } else {
                        setGraphic(null);
                    }
                }
            };
        }
    });

My idea was to override the updateItem() method and use the setGraphic() method to display the button. To indicate whether the tree item shows my own graphic node or the default, i added a boolean to my tableview structure class (Struct).

//Struct contains treetable data
class Struct {

...
//the boolean defines if the row graphics should be overridden
Boolean customRow;
...

public Boolean isCustomRow() {
    return customRow;
}}

The result which i got can you see here. I looks like the empty column cells inside the row blocks my own node.

I suspect that i also need a custom TreeTableRowSkin but i didnt find any examples how to implement this. Is there anyone who can help me to solve this?

The full code example can be found here.

GitGud
  • 11
  • 4
  • Please read https://stackoverflow.com/help/mcve and act accordingly. – kleopatra Jul 05 '18 at 13:29
  • Instead of doing both super.updateItem AND whatever you're doing with the graphic, just define your own node, I would suggest a VBox with a Label and an (optional) button and call setGraphic with your new node. – MMAdams Jul 05 '18 at 14:51

0 Answers0