Setting focus cell in TableViewer

本文探讨了如何在多列表格中通过内部事件而非代码中的激活事件列表来设置单元格焦点的方法,包括表格视图的配置、焦点单元格管理器的使用以及编辑激活策略的实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I would like to find a way to set focus to a cell in a multi-column table
by an internal Process other than the activation events listed in the code
below. One would expect that the setFocusCell(viewerCell) from
TableViewerFocusCellManager from SWTFocusCellManager would get the job
done, but it is not visible.

Suggestions for setting focus and highlighting a cell based on an internal
event?

Here's the set-up code for the TableViewer and related entities:

tableViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | 
SWT.V_SCROLL 
| SWT.BORDER | SWT.FULL_SELECTION); 
final Table table = tableViewer.getTable(); 
final TableViewerFocusCellManager mgr = new 
TableViewerFocusCellManager(tableViewer, new 
FocusCellOwnerDrawHighlighter(tableViewer)); 
final ColumnViewerEditorActivationStrategy actSupport = new 
ColumnViewerEditorActivationStrategy(tableViewer) { 
@Override 
protected boolean isEditorActivationEvent 
(ColumnViewerEditorActivationEvent event) { 
return event.eventType == 
ColumnViewerEditorActivationEvent.TRAVERSAL 
|| event.eventType == 
ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION 
|| event.eventType == 
ColumnViewerEditorActivationEvent.KEY_PRESSED 
&& (event.keyCode == SWT.CR || event.character == ' ') 
|| event.eventType == 
ColumnViewerEditorActivationEvent.PROGRAMMATIC; 
} 
}; 

TableViewerEditor.create(tableViewer, mgr, actSupport, 
ColumnViewerEditor.TABBING_HORIZONTAL 
| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | 
ColumnViewerEditor.TABBING_VERTICAL 
| ColumnViewerEditor.KEYBOARD_ACTIVATION); 

TableViewerColumn column; 
final int[] styles = { SWT.LEAD, SWT.LEAD, SWT.LEAD, SWT.LEAD, SWT.LEAD, 
SWT.LEAD, SWT.LEAD}; 
for (int columnIndex = 0; columnIndex columnIndex++) { 
column = new TableViewerColumn(tableViewer, styles[columnIndex]); 
// etc. for each column, specifying setLabelProvider and 
setEditingSupport

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值