JavaFx - 获取TableCell数据类型

时间:2016-12-14 23:56:33

标签: java javafx

如何确定javafx tablecell引用的数据类型(String,Integer,Double等)。例如。我有一个自定义单元工厂,分配给Javafx控制器中的字段,如下所示:

CustomCellFactory<Damageloop, Date> damageLoopWorkshopDueDateFactory = new CustomCellFactory ("colDamageLoopWorkshopDueDate", false);

这会调用以下类......

public class CustomCellFactory<S, T> implements Callback<TableColumn<S, T>, TableCell<S, T>>  {

    String colname;
    boolean editable;

    public CustomCellFactory (String colname, boolean editable) {
        this.colname = colname;
        this.editable = editable;
    }

    @Override
    public TableCell<S, T> call(TableColumn<S, T> arg) {
        TableCell<S, T> cell;
        if (editable == true) {
            cell = new TableCellEditable<>(colname);
        } else {
            cell = new TableCellCustom<>(colname);
        }
        return cell;
    }

}

反过来调用以下类......

public class TableCellCustom <S, T> extends TableCell<S, T> {

    String colname;

    public TableCellCustom (String colname) {
        this.colname = colname;
    }

    @Override
    protected void updateItem(T item, boolean empty) {
        super.updateItem(item, empty);
        if (empty || item == null) {
            setText(null);
            setGraphic(null);
        } else {
            setConditionalFormatting(this,item);
        }
    }

    public void setConditionalFormatting (TableCell<S,T> cell, T item) {
        //perform specific cell formatting....
    }
}

并且想要确定TableCellCustom级别的单元格的数据类型(即创建CustomCellFactory时传递的初始参数,在本例中为Date),因此可以基于此执行特定操作。我试过......

super.itemProperty().getName()

这将返回与该单元格相关的一大堆信息,如下所示:

ObjectProperty [bean: EditableTableCell[id=colDamageLoopWorkshopDueDate, styleClass=cell indexed-cell table-cell table-column]'17/01/2016', name: item, value: 2016-01-17]

但是没有引用cell数据类型。

0 个答案:

没有答案
相关问题