如何使JavaFX TableView单元格可编辑?
有很多教程,并且有很多建议可以通过扩展JavaFX单元使其可编辑来实现.一个很好的例子是这个*问题.
但是官方教程使用方法调用来创建无需编写所有代码即可通过调用
There are a lot of tutorials, And a lot of suggestions to achieve this by extending JavaFX cells to make them editable. A good one is this * question.
But the official tutorials uses a method call to create the callback without writing all that code, By calling
lastNameCol.setCellFactory(TextFieldTableCell.forTableColumn());
但是,当我在代码中执行此操作时(FormTokens是我的模型"):
However when I do this in my code (FormTokens is my "model"):
// At beginning of class declaration
@FXML private TableColumn<FormTokens, String> valuColumn;
// Later at initialization
valuColumn.setCellFactory(TextFieldTableCell.forTableColumn());
编译器说:
方法 setCellFactory(
Callback<TableColumn<FormTokens,String>,TableCell<FormTokens,String>>)
类型为 TableColumn<FormTokens,String>
不适用于参数(Callback<TableColumn<Object,String>,TableCell<Object,String>>)
The method setCellFactory(
Callback<TableColumn<FormTokens,String>,TableCell<FormTokens,String>>)
in the typeTableColumn<FormTokens,String>
is not applicable for the arguments(Callback<TableColumn<Object,String>,TableCell<Object,String>>)
如果我删除上面提到的方法调用,则所有工作都将正常进行,但TableView单元格不可编辑.我在做什么错了?
If I remove the method call mentioned above everything works well except that TableView cells are not editable. What am I doing wrong?
我刚刚发现: Javafx TableView无法编辑但是没有解决方案.如何将Callback<TableColumn<Object,...
转换为Callback<TableColumn<FormTokens,...
?
edit: I just found this: Javafx TableView can not be edited But there are no solutions. How do I cast Callback<TableColumn<Object,...
to Callback<TableColumn<FormTokens,...
?
为通用参数明确指定确切类型为
Specify the exact type explicitly for generic parameter as
valuColumn.setCellFactory(TextFieldTableCell.<FormTokens>forTableColumn());