How to set Focus to the first row in a JTable which is inside a JScrollPane
24,326
Solution 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);
Solution 2
try with
myTable.changeSelection(row, column, false, false);
depends of ListSelectionModel
Author by
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
I have a
JTable
inside aJScrollPane
. 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 theJScrollPane
and on pressing tab the focus enters into table's first row. I dont want to usesetRowSelectionInterval(0,0)
andsetColumnSelectionInterval(0,0)
as my requirement is different from that. -
Admin almost 11 yearsThanks a lot for the replies