2011-11-03 94 views
2

我是JFace的新蜜蜂。SWT JFace:如何使TableViewer始终选择一行?

我的表查看页头代码:

viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL 
| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); 

而且我有一个TableCursor创建成一排来选择不同的细胞。

Select a row in the table

后来我发现,这是很尴尬的,允许用户“选择什么”。 :-(

Select nothing in the table, very ugly right?

我想知道如果有一个SWT属性来设置或一些编码解决方案,以强制用户总是选择行。

回答

3

您必须手动剿取消选择,请参阅下面的代码片段:

viewer.addSelectionChangedListener(new ISelectionChangedListener() { 

    private boolean update; 

    private ISelection lastSelection; 

    @Override 
    public void selectionChanged(SelectionChangedEvent event) { 
     if (event.getSelection().isEmpty() && !update) { 
      update = true; 
      v.setSelection(lastSelection); 
      update = false; 
     } else if (!event.getSelection().isEmpty()) { 
      lastSelection = event.getSelection(); 
     } 

    } 
}); 
+0

这个真正伟大的作品非常感谢您! –

相关问题