javafx中TableView自定义单元格-checkbox

cd_tc_haveSymbol.setCellFactory(new Callback<TableColumn<CommunicationData,Boolean>, TableCell<CommunicationData,Boolean>>()
{
    @Override
    public TableCell<CommunicationData, Boolean> call(TableColumn<CommunicationData, Boolean> param)
    {
        TableCell<CommunicationData, Boolean> cell = new TableCell<CommunicationData, Boolean>()
        {
            @Override
            protected void updateItem(Boolean item, boolean empty)
            {
                super.updateItem(item, empty);
                //清空样式
                setText(null);
            setGraphic(null);
            
            //增加样式
                if(empty == false && item != null)
                {
                    HBox hBox = new HBox();
                    hBox.setAlignment(Pos.CENTER);
                    
                    //赋值
                    CheckBox cb = new CheckBox();
                    cb.setSelected(item);
                    
                    if(this.getTableRow() != null)
                    {
                        CommunicationData cd = cdData.get(this.getTableRow().getIndex());
                        cb.selectedProperty().bindBidirectional(cd.getHaveSymbolProperty());
                    }
                    
                    hBox.getChildren().add(cb);
                    this.setGraphic(hBox);
                }
            }
        };
        return cell;
    }
});

 

posted @ 2020-04-01 21:24  qinggua  阅读(1339)  评论(0编辑  收藏  举报