如何将Focus设置为JScrollPane中JTable的第一行 [英] How to set Focus to the first row in a JTable which is inside a JScrollPane

查看:99
本文介绍了如何将Focus设置为JScrollPane中JTable的第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 JScrollPane 中有一个 JTable 。我把它放在一个面板里面。一旦面板加载,我希望JTable中的第一行获得焦点但是默认情况下焦点转到 JScrollPane 并且在按下选项卡时焦点进入表格的第一行。
我不想使用 setRowSelectionInterval(0,0) setColumnSelectionInterval(0,0)作为我的要求与此不同。

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);

这篇关于如何将Focus设置为JScrollPane中JTable的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆