My JTable has couple of rows listed. For the first time when i invoke getselectedRow() it gives me the correct result but after that it always returns me -1.
After the first call to getSelectedRow() I am deleting the selected row and then I am trying to refresh the table and that's what seems to be causing this issue. If i remove the code for refreshing the table it works fine again.
For refreshing the table, first i invoke
model.getDataVector().removeAllElements();
and after that I rebuild the table as i would for the first time ie hitting the database and inserting rows into model.
Any suggestions what I need to do?
For the first time when i invoke getselectedRow() it gives me the correct result but after that it always returns me -1.
this is possible only in the case that
isn't any row selected
JTable is empty
you have to test if (table.getSelectedRow() != -1) {
before code execution
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.