10

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.

Mat
  • 202,337
  • 40
  • 393
  • 406
Revathi Revu
  • 101
  • 1
  • 1
  • 3
  • you want to edit first cell or just want it selected? – Luna Jul 07 '12 at 05:12
  • 1
    _as my requirement is different from that_ - then: what exactly _is_ your requirement? – kleopatra Jul 07 '12 at 10:08
  • I just want it to be selected, n especially the first cell of the first row must be focused. If i print the first focusable component, it prints JScrollPane, i want it to return first row in a Jtable. – Revathi Revu Jul 08 '12 at 14:33

2 Answers2

18

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);
adelarsq
  • 3,718
  • 4
  • 37
  • 47
Luna
  • 956
  • 4
  • 15
  • 28
8
  • try with myTable.changeSelection(row, column, false, false);

  • depends of ListSelectionModel

mKorbel
  • 109,525
  • 20
  • 134
  • 319