Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keep first row in jtable selected as default

Tags:

java

swing

jtable

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?

like image 686
Nikhil Avatar asked Mar 27 '26 15:03

Nikhil


1 Answers

have look at method for 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

like image 106
mKorbel Avatar answered Mar 29 '26 03:03

mKorbel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!