为了获取 jTable 中选定的行,我使用了 MouseEvent (MouseClicked
)。这工作正常,并在单击表格后给我正确的行号。
为了在 jTable 中导航,我添加了一个新的监听器 (KeyPressed
)。如果我按向上键,则行号不会增加。如果我再次按向上键,行数将会更新,但它是之前的行数。
private void jTable1KeyPressed(java.awt.event.KeyEvent evt) {
if(evt.getKeyCode() == evt.VK_UP){
System.out.println("Key UP" + jTable1.getSelectedRow());
}
if(evt.getKeyCode() == evt.VK_DOWN){
System.out.println("Key DOWN" + jTable1.getSelectedRow());
}
}
这是简单的代码。如果我单击表的第一行并按向下键,则输出为“Key DOWN0”。但第二行被选择,输出应该是“Key DOWN1”。
最佳答案
To get the selected row in a jTable, I used a MouseEvent (MouseClicked). That works fine and give me the correct rownumber after clicking into the table.
To navigate trough the jTable, I added a new Listener (KeyPressed). If I press the up key, the rownumber is not been increased. If I press the up key again, the rowcount will be updated, but it is the rowcount from previously
.
我认为你需要
关于java - 使用向上/向下键导航后,jTable 的行号错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18204207/