[英]SWT how to have table that highlights entire row with single click, and edits cell with double click?
SWT 新手在這里。 所以,我想要的是能夠突出顯示整行,以及能夠 select 多行,並使其雙擊編輯單元格。 是否需要focusCellManager? 相關代碼:
編輯器激活事件
final ColumnViewerEditorActivationStrategy actSupport =
new ColumnViewerEditorActivationStrategy(this)
{
@Override
protected boolean isEditorActivationEvent
(ColumnViewerEditorActivationEvent event)
{
return event.type ==
ColumnViewerEditorActivationEvent.TRAVERSAL
|| event.eventType ==
ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
|| event.eventType ==
ColumnViewerEditorActivationEvent.KEY_PRESSED
|| event.eventType ==
ColumnViewerEditorActivationEvent.PROGRAMMATIC;
}
};
創建 TableViewerEditor
TableViewerEditor.create(this,
mgr,
actSupport,
ColumnViewerEditor.TABBING_HORIZONTAL|
ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR|
ColumnViewerEditor.TABBING_VERTICAL|
ColumnViewerEditor.KEYBOARD_ACTIVATION);
經理(focusCellManager)的代碼:
focusCellOwnerDrawHighlighter drawHighlighter = new FocusCellOwnerDrawHighlighter(this);
final TableViewerFocusCellManager mgr = new TableViewerFocusCellManager(this, null);
tableViewer(沒有出現在之前的截圖中,因為 tableViewer 是由另一個 class 擴展的,我們使用另一個 class,所以我不想混淆你):
TableViewer vwr = new TableViewer(tableComposite,SWT.BORDER|SWT.FULL_SELECTION|SWT.MULTI);
在表格列上使用EditingSupport
並結合以下 TableViewerEditor 似乎對我有用:
TableViewer viewer = new TableViewer(tableComp, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) {
@Override
protected boolean isEditorActivationEvent(final ColumnViewerEditorActivationEvent event) {
return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
|| event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
|| event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED
|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
}
};
int feature = ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_HORIZONTAL
| ColumnViewerEditor.KEYBOARD_ACTIVATION
| ColumnViewerEditor.TABBING_CYCLE_IN_VIEWER;
TableViewerEditor.create(viewer, actSupport, feature);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.