Skip to content

Edit the cell value at a dynamic TableView?

Is it possible to edit a cell value in a dynamic TableView (dynamic rows and dynamic columns)?

All I found on the internet was some editable TextFields over the cells.
However, I want to edit the value in the table and then update my List with the new data.

I’m using IntelliJ IDEA 13.1.4 , JavaFX Scene Builder 2.0 and the newest JavaFX version.

Here is the code, where I create the dynamic rows and columns:

public List<String[]> jdata = new LinkedList<>(); //Here is the data
private TableView<String[]> sourceTable;
private ObservableList<String[]> srcData;

int clms;
    public void showTable(Convert cnv) {
        clms = cnv.getColums(); //number of the columns

        for (int i = 0; i < clms; i++) {
            TableColumn<String[], String> firstNameCol = new TableColumn<>("tC"+(i+1)+" t");
            int index = i ;
            firstNameCol.setCellValueFactory(cellData -> {
                String[] rowData = cellData.getValue();
                if (index >= rowData.length) {
                    return new ReadOnlyStringWrapper("");
                } else {
                    String cellValue = rowData[index];
                    return new ReadOnlyStringWrapper(cellValue);
        srcData = FXCollections.observableList(jdata);



Just do

firstNameCol.setOnEditCommit(event -> {
    String[] row = event.getRowValue();
    row[index] = event.getNewValue();
User contributions licensed under: CC BY-SA
7 People found this is helpful