How to set Focus to the first row in a JTable which is inside a JScrollPane

北战南征 提交于 2019-11-30 03:23:41

问题


I have a JTable inside a JScrollPane. I have put this inside a panel. As soon the panel loads I want the first row in the JTable to get the focus BUT by default the focus goes to the JScrollPane and on pressing tab the focus enters into table's first row. I dont want to use setRowSelectionInterval(0,0) and setColumnSelectionInterval(0,0) as my requirement is different from that.


回答1:


If you want to edit cell you can use,

jTable1.requestFocus();
jTable1.editCellAt(row,column);

Or else you want to just select the row, you can use,

jTable1.requestFocus();
jTable1.changeSelection(row,column,false, false);



回答2:


  • try with myTable.changeSelection(row, column, false, false);

  • depends of ListSelectionModel



来源:https://stackoverflow.com/questions/11365294/how-to-set-focus-to-the-first-row-in-a-jtable-which-is-inside-a-jscrollpane

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!