5
votes

I have JTable and rows in it. By default first row is selected and focus is in it. How can I deselect first row and change focus to somewhere else that .addListener(new RowSetListener() will work in first row too.

I already try:

tableZaposlenciView1.setRowSelectionAllowed(true);        
//tableZaposlenciView1.getSelectionModel().clearSelection();
//tableZaposlenciView1.setColumnSelectionInterval(0,0);
//tableZaposlenciView1.setRowSelectionInterval(false,false);        
tableZaposlenciView1.changeSelection(0,0,false,false);
tableZaposlenciView1.requestFocus();

but it is not working.

2
Well, if you want to change to something OTHER than (0,0), maybe you shouldn't use (0,0) as arguments to changeSelection(), am I right?perp
i can try 12, 2 but is the samesenzacionale
changeSelection(...) works perfectly fine for me. Post your SSCCE (sscce.org) demonstrating the problem. We can't keep guessing what you may or may not be doing.camickr

2 Answers

3
votes

Have a look at JTable's changeSelection() method. I believe it does what you want.

EDIT: If you want to clear the selection:

JTable table = ...;
table.getSelectionModel().clearSelection();
0
votes

if someone else have similar problem with ADF and JTable here is solution. I achieve that by overriding first() on the VO impl. my problem can be solved.

That comes in handy in many situations:

  • no selection after refresh (just return null from first())
  • reselect a particular row after refresh (before refresh, store a row key, after refresh in first() if stored key is found, navigate to that row and return that from first())
  • find next matching row for user to work on after refresh of a worklist
  • avoid costly detail executions in a VL situation