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

JavaFX/TableView:3个不同的表使用相同的TableCellDouble,但需要3个TableCellDouble类。。。如何减少到1x?,javafx,tableview,tablecell,Javafx,Tableview,Tablecell,在我的应用程序中有3个不同的表,它们包含具有自己TableCell的双值列。 在所有三个表中,双值的输入和显示是相同的。 不幸的是,我不得不创建相同的TableCellDouble类3x,只是因为第1行代码不同 //3x different data class with the getters and setters DataLineExpectedValue.java DataLineInputMoney.java DataLinePayPosition.java //3x T

在我的应用程序中有3个不同的表,它们包含具有自己TableCell的双值列。 在所有三个表中,双值的输入和显示是相同的。 不幸的是,我不得不创建相同的TableCellDouble类3x,只是因为第1行代码不同

//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(); });
//使用getter和setter实现3个不同的数据类
DataLineExpectedValue.java
DataLineInputMoney.java
DataLinePayPosition.java
//3x TableCellDouble,尽管除第一行外,这些都是相同的
TableCellDouble_expectedValue.java:
公共类TableCellDoubleExpectedValue扩展了DataLineExpectedValue的TableCell{//
私有MyTextFieldOnlyDoubleWithComma textFieldOnlyDouble=新MyTextFieldOnlyDoubleWithComma();
public TableCellDouble_expectedValue(){…}
@凌驾
受保护的void updateItem(字符串项,布尔空){…}
@凌驾
public void startEdit(){…}
@凌驾
public void committedit(字符串newValue){…}
@凌驾
public void cancelEdit(){…}
}
TableCellDouble\u inputMoney.java:
公共类TableCellDouble_inputMoney扩展了DataLineInputMoney的TableCell{//
其余代码与上面的代码相同。
...
}
TableCellDouble_payPosition.java:
公共类TableCellDouble_payPosition扩展了DataLinePayPosition的TableCell{//
其余代码与上面的代码相同。
...
}
//问题:
//如何获得3个几乎相同的课程:
//TableCellDouble_expectedValue.java,
//TableCellDouble_inputMoney.java和
//TableCellDouble_payPosition.java
//=>在名为TableCellDouble.java的类中
//然后在应用程序中的所有表中统一使用它。
//例如,代替:
table01Column01.setCellFactory((param)->{返回新的TableCellDouble_inputMoney();});
table02Column04.setCellFactory((param)->{返回新的TableCellDouble_expectedValue();});
table03Column11.setCellFactory((param)->{返回新的TableCellDouble_payPosition();});
//那么:
table01Column01.setCellFactory((param)->{返回新的TableCellDouble();});
table02Column04.setCellFactory((param)->{返回新的TableCellDouble();});
table03Column11.setCellFactory((param)->{返回新的TableCellDouble();});
使用通用定义

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

... your code

}
公共类TableCellDouble扩展TableCell{
…您的代码
}
使用通用定义

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

... your code

}
公共类TableCellDouble扩展TableCell{
…您的代码
}