Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make JavaFX TableView cells editable?

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 stackoverflow question.
But the official tutorials uses a method call to create the callback without writing all that code, By calling

lastNameCol.setCellFactory(TextFieldTableCell.forTableColumn());

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());

Compiler says:

The method setCellFactory( Callback<TableColumn<FormTokens,String>,TableCell<FormTokens,String>>)
in the type TableColumn<FormTokens,String>
is not applicable for the arguments
(Callback<TableColumn<Object,String>,TableCell<Object,String>>)

If I remove the method call mentioned above everything works well except that TableView cells are not editable. What am I doing wrong?

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,...?

like image 288
hkoosha Avatar asked Oct 12 '13 14:10

hkoosha


People also ask

How to select a row in TableView JavaFX?

To select a row with a specific index you can use the select(int) method. Here is an example of selecting a single row with a given index in a JavaFX TableView: selectionModel. select(1);


1 Answers

Specify the exact type explicitly for generic parameter as

valuColumn.setCellFactory(TextFieldTableCell.<FormTokens>forTableColumn());
like image 90
Uluk Biy Avatar answered Sep 30 '22 08:09

Uluk Biy