简体   繁体   中英

remove focus from JTable first row

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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