I have a JTable and I am inserting rows to that JTable dynamically.
After some user intervention, a new row will be inserted .Then I will call a function with parameter as selected row number and inside that function, I have some code which will update the same row accordingly. Each row insertion and row value update code will run in a separate thread.
public void updateRow(int row,JTable myTable)
String text = "";
//After lot of processing, setting the table cell value at the 'row' on the 4th column
myTable.setValueAt(text, row, 4);
The issue I am facing is as follows,
If the user deleting any row, then row's position will change and at that time if the function `updateRow()` trying to update some other row, then it will fail because of change of row count.
Lets say I have 3 row at a time and each row's updateRow is in progress.
updateRow(0,userTable);//For the 1st row
updateRow(1,userTable);//For the 2nd row
updateRow(2,userTable);//For the 3rd row
and assume 2nd row's updateRow() is completed. This will cause issue in updateRow() function of 3rd row. Because, it has the row value as '2' . Since the 3rd row got deleted, there is no 3rd row and which in turn cause the following code to fail
myTable.setValueAt(text, row, 4);//Currently, row has the value as '2'
Can anyone suggest me how can I keep track of the row update with row values accordingly, even if the row's position got changed dynamically ?
Thanks in advance. "Each row insertion and row value update code will run in a separate thread" - That is an incredibly bad idea. Swing is not thread safe and you are expected to update the UI only from the context of the Event Dispatching Thread
以上就是Updating JTable row dynamically after the deletion successive rows的详细内容，更多请关注web前端其它相关文章！