Is it possible to edit data in jtable and save it?

I would like to know if it is possible to view my values โ€‹โ€‹through JTable and then edit them there?

+3
source share
3 answers

isCellEditable (int row, int col) This method determines which rows and columns the user is allowed to modify. Since this method returns a boolean if all cells are editable, it simply returns true. To prevent JTable from changing a specific column or row value, it returns false from this method. The following code allows you to display only one column, allowing you to change the remaining columns.

// Make column one noneditable

while allowing the user to edit at
all // other columns.
If (col == 1){
return false;
}
else{
return true;
}

public void setValueAt(Object value, int row, int col)

, . , , , . , . , , , , . JTable, . , , JTable. , . ( ) , JTable.

// Update the array of objects with
// the changes the user has just entered in a cell.
// Then notify all listeners (if any) what column
// and row has changed. Further processing may take place there.

rowData[row][col] = value;
fireTableDataChanged();
+4

Yes it is possible. Basically, jtable is editable. You can check the TableModel.isCellEditable () method. After editing, you can save the table value in a two-dimensional array and save it in the database. int i; int j;

    String tableData = new String[row count][column count];

    for(i = 0; i < row count; i++)
    {
        for(j = 0; j < 3; j++)
        {
            tableData[i][j] = table.getValueAt(i, j).toString();
        }
    }
+2
source

Source: https://habr.com/ru/post/1743472/


All Articles