简体   繁体   English

将jtable中的第一行保留为默认值

[英]keep first row in jtable selected as default

table.setRowSelectionInterval(0, 0);

I had tried the above code, but when I use this code I cannot retrieve the values using the below code: 我已经尝试了上面的代码,但是当我使用此代码时,无法使用以下代码检索值:

int col = table.getSelectedColumn();
int row = table.getSelectedRow();
finalOID=(String)table.getModel().getValueAt(row, col);
System.out.println("first oid:"+finalOID);

How can I solve this? 我该如何解决?

have look at method for JTable 看一下JTable的方法

table.changeSelection(0, 0, false, false);

depends of Selection Mode 取决于选择模式

method must be invoked on Event Dispatch Thread , more in the Oracle tutorial Concurency in Swing 方法必须在Event Dispatch Thread上调用,有关更多信息,请参见Oracle教程Conwingency in Swing

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

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