In a tree-table-view there are child items that have in turn other child items. I need to customize, say, the text of certain cells of those pseudo-root items.

Is there a way to assign a css class/style to those items?

Update:
Ok, got it working with the following cellFactory:

treeTblColumnName.setCellFactory(new Callback<TreeTableColumn<FileModel, String>, TreeTableCell<FileModel, String>>() {
        @Override
        public TreeTableCell<FileModel, String> call(TreeTableColumn<FileModel, String> param) {
            TreeTableCell<FileModel, String> cell = new TreeTableCell<FileModel, String>() {

                @Override
                protected void updateItem(String t, boolean bln) {
                    super.updateItem(t, bln); //To change body of generated methods, choose Tools | Templates.                        

                    System.out.println(this.getTableColumn().);
                    Label lbl = new Label(t);
                    lbl.setStyle("-fx-font-weight: bold; -fx-font-size: 14pt; -fx-text-fill: white;");
                    setGraphic(lbl);

                }

            };
            return cell;
        }

    });

Now, how can I distinguish between classes? FileModel is an interface which is implemented by several classes. In this cellFactory I need to know what type is the current cell->item in order to apply different styling on it.
Thanks.

有帮助吗?

解决方案

You can use instanceof:

FileModel fileModel = getTreeTableRow().getItem();
if(fileModel instanceof ExeFileModel){
   //set style here
} else if(fileModel instanceof TxtFileModel){
   //use another style here
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top