JavaFX/TableView:3 个不同的表使用相同的 TableCellDouble,但 3x TableCellDouble 类 是必要的...如何减少到 1x?

JavaFX/TableView: 3 different tables use the same TableCellDouble, but 3x TableCellDouble classes necessary ... how to reduce to 1x?

我的应用程序中有 3 个不同的表,这些表包含带有自己的 TableCell 的双值列。 double 值的输入和显示在所有三个表中都是相同的。 不幸的是,我不得不创建相同的 TableCellDouble class 3x,只是因为第一行代码不同。

//3x different data class with the getters and setters  
DataLineExpectedValue.java  
DataLineInputMoney.java  
DataLinePayPosition.java

//3x TableCellDouble, although these are the same except for the first line
TableCellDouble_expectedValue.java:
public class TableCellDouble_expectedValue extends TableCell<DataLineExpectedValue, String> { //for DataLineExpectedValue

    private MyTextFieldOnlyDoubleWithComma textFieldOnlyDouble = new MyTextFieldOnlyDoubleWithComma();

    public TableCellDouble_expectedValue() { ... }

    @Override
    protected void updateItem(String item, boolean empty) { ... }

    @Override
    public void startEdit() { ... }

    @Override
    public void commitEdit(String newValue) { ... }

    @Override
    public void cancelEdit() { ...}
}


TableCellDouble_inputMoney.java:
public class TableCellDouble_inputMoney extends TableCell<DataLineInputMoney, String> { //for DataLineInputMoney
    The rest is the same code as above.
    ...
}


TableCellDouble_payPosition.java:
public class TableCellDouble_payPosition extends TableCell<DataLinePayPosition, String> { //for DataLinePayPosition
    The rest is the same code as above.
    ...
}

//Question:  
//How to get the 3 almost same classes: 
//TableCellDouble_expectedValue.java, 
//TableCellDouble_inputMoney.java and
//TableCellDouble_payPosition.java  
//=> in a class called TableCellDouble.java  
//And then use it uniformly in all tables in the application.

//E.g. Instead of:
table01Column01.setCellFactory( (param) -> { return new TableCellDouble_inputMoney(); });
table02Column04.setCellFactory( (param) -> { return new TableCellDouble_expectedValue(); });
table03Column11.setCellFactory( (param) -> { return new TableCellDouble_payPosition(); });

//Then uniformly so:
table01Column01.setCellFactory( (param) -> { return new TableCellDouble(); });
table02Column04.setCellFactory( (param) -> { return new TableCellDouble(); });
table03Column11.setCellFactory( (param) -> { return new TableCellDouble(); });

使用通用定义

public class TableCellDouble<T> extends TableCell<T, String> {

... your code

}