如何确定javafx tablecell引用的数据类型(String,Integer,Double等)。例如。我有如下分配给场中一个JavaFX控制器中的自定义单元格工厂:JavaFx - 获取TableCell数据类型
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时通过,在这种情况下的日期初始参数),以便SP基于此可以执行特殊操作。我曾尝试...
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]
但对细胞的数据类型没有提及。
你能不能给一点在这里更多的环境?本书的答案是数据类型是'T',但我猜这不是你的意思...... –
@James_D更新提供更多的上下文。而且我绝对不会在T之后! – Josh