简体   繁体   English

如何将Focus设置为JScrollPane中JTable的第一行

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

I have a JTable inside a JScrollPane . 我在JScrollPane有一个JTable 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. 一旦面板加载,我希望JTable中的第一行获得焦点但是默认情况下焦点转到JScrollPane并且在按下tab时焦点进入表格的第一行。 I dont want to use setRowSelectionInterval(0,0) and setColumnSelectionInterval(0,0) as my requirement is different from that. 我不想使用setRowSelectionInterval(0,0)setColumnSelectionInterval(0,0)因为我的要求与此不同。

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); 尝试使用myTable.changeSelection(row, column, false, false);

  • depends of ListSelectionModel 取决于ListSelectionModel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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