user462872
user462872

Reputation: 329

how to set a row of Swing Jtable to 'selected'?

I managed to search but did not get the answer I wanted. Please allow me writing here.

Let's say I have a Swing JTable, each row has an ID (also other data). I know I can find out the row with a given ID, by implementing a function in tableModel. My question is, if I have an ID, how can I set the row to 'selected' status in JTable? it should be equivalent to 'using mouse to single click on that row'.

It looks there is not a method like 'setRowToSelected(int rowIndex)' in JTable?

Upvotes: 2

Views: 6157

Answers (1)

camickr
camickr

Reputation: 324088

it should be equivalent to 'using mouse to single click on that row'.

table.changeSelection(...);

This will cause the row to be selected and the cell selection to change.

The other option that was pointed to in another thread was:

table.setRowSelectionInterval(...);

This will just select the row, but the current cell selection will remain.

Upvotes: 7

Related Questions