Forums Register Login

delete row from Jtable using AbstractTableModel

+Pie Number of slices to send: Send
Hi all, I have the following


Now after I click the delete button, that deleted record is still displayed in the table view but as "java.lang.Object@..." for the field. I want to completely remove the just deleted row from the view.

Also I noticed if there are say 20 records, I delete the 5th record. The 20th record disappears with the 5th record display as "java.lang.Object...". If I managed to remove the 5th record, would I able to see the 20th record again?

Oh the removeRow method is practically the same as the DefaultTableModel implementation. But it doesn't look right.
+Pie Number of slices to send: Send
 

K. Tsang wrote:Hi all, I have the following


Now after I click the delete button, that deleted record is still displayed in the table view but as "java.lang.Object@..." for the field. I want to completely remove the just deleted row from the view.

Also I noticed if there are say 20 records, I delete the 5th record. The 20th record disappears with the 5th record display as "java.lang.Object...". If I managed to remove the 5th record, would I able to see the 20th record again?

Oh the removeRow method is practically the same as the DefaultTableModel implementation. But it doesn't look right.



MyTableModel.removeRow() needs to call the fireTableRowsDeleted() method. What this does is notify the listeners (i.e. the JTable) so they can update themselves.

Btw, it's hard to tell from what you've shown us, but it appears that you are storing all the data twice: once in MyTableModel's map and once in the data object. Wouldn't it be easier to just store it once? For instance, MyTableModel could simply refer to data.
+Pie Number of slices to send: Send
Hi Brian, you are right about storing the data twice, so I removed the map object. Now in my deleteRow() method, I did call the fireTableRowsDeleted() method. But doesn't seem to work. Once I remove the map, I use a 2D array to populate the table's data. Now the deleteRow() method looks like this:



Now once I delete the row the table view becomes blank for that particular row (from line 11 above). But actually I really want to remove that from the 2D array. Since 2D array size is fixed, I could repopulate the 2D array from scratch by calling my table model's constructor which would get the non deleted row record number from the data object. This ends up the very last record missing once I delete row.

I suggest huckleberry pie. But the only thing on the gluten free menu is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 15866 times.
Similar Threads
JTable
JTable ........
JTable
Jtable
Boolean value in JTable display problem after delete
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 08:59:59.