使用 setRowSelectionInterval(int, int) 后无法通过箭头键导航 JTable
我正在扩展 JTable,并且有一个 populateData() 方法,用于将数据加载到表模型中。在这种方法中,我使用:
setRowSelectionInterval(tableRow, tableRow);
它正在按我想要的方式工作,即突出显示第一行。但有一个问题:我无法通过向下箭头键将选择移动到下一行。我必须用鼠标单击任何行(甚至突出显示的行)才能通过箭头键进行导航。
void populateData(Collection<Book> b) {
myModel.populateData(b);
if (myModel.getRowCount() > 0) {
setRowSelectionInterval(0, 0);
}
}
注意:我仅启用行选择。列和单元格选择被禁用。
有什么想法如何解决这个问题吗?
提前致谢。
I'm extending JTable and I have a populateData() method that I'm using to load data into the table model. In this method I'm using:
setRowSelectionInterval(tableRow, tableRow);
And it is working as I want it to, which is to highlight the first row. But there is one problem: I cannot move the selection to the next row by the down arrow key. I have to click on any row (even the one that is highlighted) with the mouse to be able to navigate by the arrow keys.
void populateData(Collection<Book> b) {
myModel.populateData(b);
if (myModel.getRowCount() > 0) {
setRowSelectionInterval(0, 0);
}
}
Note: I'm enabling only row selections. Column and cell selections are disabled.
Any ideas how to fix this?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜想焦点不在桌子上,所以它不会对按键做出反应。您可能需要添加:
如果这不起作用,请尝试使用而不是 setRowSelectionInterval(...) :
I would guess focus in not on the table so it doesn't react to key presses. You may need to add:
If this doesn't work the instead of setRowSelectionInterval(...) try using: