[英]Invoking getSelectedRow method on does not return consistent results
My JTable has couple of rows listed. 我的JTable列出了几行。 For the first time when i invoke getselectedRow() it gives me the correct result but after that it always returns me -1.
这是我第一次调用getselectedRow()时它给了我正确的结果,但之后它总是返回-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. 在第一次调用getSelectedRow()后,我正在删除所选行,然后我正在尝试刷新表,这似乎是导致此问题的原因。 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.
这是我第一次调用getselectedRow()时它给了我正确的结果,但之后它总是返回-1。
this is possible only in the case that 只有在这种情况下才有可能
isn't any row selected 不是任何行选择
JTable is empty JTable是空的
you have to test if (table.getSelectedRow() != -1) {
before code execution 你必须在代码执行之前测试
if (table.getSelectedRow() != -1) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.