Skip to content
Advertisement

Using custom TableModel make isCellEditable true for a particular row on button click

MY Table

I have a table like above. Initially all the cells except button column are not editable. I have created the table using custom TableModel. My isCellEditable in custom TableModel looks like this:

JavaScript

But when I click on the Edit button of each row a JDialog will pop up with that row (by constructing a JTable in this dialog with only one row.) I can update the cell values in this JDialog’s table. and then update them in the respective cells of that row.

JDialog's Table

I successfully updated the main table’s row after updating here, only if my isCellEditable return true. But this should not happen. Only when I click then I should be able to change isCellEditable of the row as Editable and update and then make it uneditable.

I have seen the following post but was unable to implement it.

Advertisement

Answer

Fleshing out my comment to the question:

there’s no need to tweak the editability of the full model: create another model populated by the filtered (column-wise) row of the original, make that other editable and on commit let it write back the changed values to the original

with a bit of code:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement