javafx cell在初始化过程中如何获得其他列的值

来源:互联网 发布:龙门县平陵镇网络问政 编辑:程序博客网 时间:2024/06/05 15:55

有的时候在初始化一个tableview的时候,需要根据列的值来做出判断,是插入什么控件,或者是行的显示 颜色,前提是我们必须要获得该行,该列。

cell.setCellFactory(new Callback<TableColumn<TableBean,String>, TableCell<TableBean,String>>() {            @Override            public TableCell<TableBean, String> call(TableColumn<TableBean, String> param) {                return new EditingCell(); //写个类继承TableCell                // TODO Auto-generated method stub            }        });

覆写updateItem方法,这个是渲染方法。indexProperty()获取当前的index,有了这个值就轻松多了。

public class EditingCell extends TableCell<TableBean, String> {    @Override    protected void updateItem(String item, boolean empty) {        System.out.println(indexProperty());        super.updateItem(item, empty);        //Button bt=new Button("按钮");        //setGraphic(bt);    }}
阅读全文
0 0
原创粉丝点击