2

I'm new to JavaFX 8 and tried to implement a TreeTableView with some jfxtras controls in my second and third column. Therefore I set up the cell factories of those columns with custom TreeCells e.g. like this:

col3.setCellFactory(new Callback<TreeTableColumn<Object, String>, TreeTableCell<Object, String>>() {
        @Override
        public TreeTableCell<Object, String> call(TreeTableColumn<Object, String> param) {
            TreeTableCell<Object, String> cell = new TreeTableCell<Object, String>() {
                private ColorPicker colorPicker = new ColorPicker();
                @Override
                protected void updateItem(String t, boolean bln) {
                    super.updateItem(t, bln);               
                    setGraphic(colorPicker);                        
                }
            };
            return cell;
        }
    });

Now I can see the ColorPickers and can use them, but the column somehow does not react on expanding or collapsing the nodes of column 1 (which shows String information out of POJOs). So e.g. if I collapse the whole tree, the third column still shows all ColorPickers.

So what else is necessary to get the columns 'synced'?

Thank you!!

4

1 回答 1

1

当单元格显示的项目发生变化时,updateItem(...)调用该方法。如果单元格是空的(例如因为用户折叠了上面的单元格),第二个参数将是true; 您需要检查这一点并取消设置图形。

所以:

col3.setCellFactory(new Callback<TreeTableColumn<Object, String>, TreeTableCell<Object, String>>() {
        @Override
        public TreeTableCell<Object, String> call(TreeTableColumn<Object, String> param) {
            TreeTableCell<Object, String> cell = new TreeTableCell<Object, String>() {
                private ColorPicker colorPicker = new ColorPicker();
                @Override
                protected void updateItem(String item, boolean empty) {
                    super.updateItem(item, empty);  
                    if (empty) {
                        setGraphic(null);
                    } else {             
                        setGraphic(colorPicker);     
                    }                   
                }
            };
            return cell;
        }
    });
于 2015-07-08T15:44:58.730 回答