简体   繁体   中英

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

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.

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);
  • try with myTable.changeSelection(row, column, false, false);

  • depends of ListSelectionModel

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM