简体   繁体   English

从JTable第一行删除焦点

[英]remove focus from JTable first row

I have JTable and rows in it. 我有JTable和行。 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. 如何取消选择第一行并将焦点更改为.addListener(new RowSetListener()也将在第一行中工作的其他位置。

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. 看看JTable的changeSelection()方法。 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. 如果其他人有与ADF和JTable类似的问题,这里是解决方案。 I achieve that by overriding first() on the VO impl. 我通过覆盖VO impl上的first()实现了这一点。 my problem can be solved. 我的问题可以解决。

That comes in handy in many situations: 这在许多情况下派上用场:

  • no selection after refresh (just return null from first()) 刷新后没有选择(只从first()返回null)
  • 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()) 刷新后重新选择一个特定的行(在刷新之前,存储行键,在first()中刷新后如果找到存储的键,则导航到该行并从first()返回该行)
  • find next matching row for user to work on after refresh of a worklist 找到下一个匹配行,供用户在刷新工作清单后进行处理
  • avoid costly detail executions in a VL situation 避免在VL情况下执行昂贵的详细信息

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

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