如何在不使用鼠標監聽器的情況下編輯SWT表值?可編輯的SWT表
Q
可編輯的SWT表
3
A
回答
7
在下面的鏈接幫助中做了TableEditor
片段嗎?
在TableEditor
部分的第一個示例使用上表中的SelectionListener
(不像使用你提到你不想MouseDown事件的第二個例子)
也許你可以利用TraverseListener
或KeyListener
也可以幫助你實現你想要的。
4
final int EDITABLECOLUMN = 1;
tblProvisionInfo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Clean up any previous editor control
final TableEditor editor = new TableEditor(tblProvisionInfo);
// The editor must have the same size as the cell and must
// not be any smaller than 50 pixels.
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
editor.minimumWidth = 50;
Control oldEditor = editor.getEditor();
if (oldEditor != null)
oldEditor.dispose();
// Identify the selected row
TableItem item = (TableItem) e.item;
if (item == null)
return;
// The control that will be the editor must be a child of the
// Table
Text newEditor = new Text(tblProvisionInfo, SWT.NONE);
newEditor.setText(item.getText(EDITABLECOLUMN));
newEditor.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent me) {
Text text = (Text) editor.getEditor();
editor.getItem()
.setText(EDITABLECOLUMN, text.getText());
}
});
newEditor.selectAll();
newEditor.setFocus();
editor.setEditor(newEditor, item, EDITABLECOLUMN);
}
});
這裏tblProvision
是你的表的名字。你現在可以點擊它來編輯你的表格。我已申報EDITABLECOLUMN
。這是你想編輯的column
。
1
如果你可以使用的JFace以及不只是疼痛SWT,看看在JFace Snippets,尤其是
- Snippet036FocusBorderCellHighlighter - 通過重點邊框顯示一次凸顯了當前選定單元格演示鍵盤導航新的小區導航支持
- Snippet034CellEditorPerRowNewAPI的更多的靈活性 - 在一列展示不同CellEditor中-類型與JFace的觀看者的3.3-API
0
您可以獲取或設置項的值,例如:
Table table = new Table(parent, SWT.NONE);
TableItem item = new TableItem(table, SWT.NONE);
item.setText("My new Text");
0
我建議你給我們TableViewer,它是它,你可以使用數據綁定很容易得非常強大的表格。
相關問題
- 1. SWT表格無法編輯
- 2. Java SWT WYSIWYG HTML編輯器
- 3. jQuery可編輯/不可編輯表格
- 4. angularjs的可編輯表格
- 5. 使用SWT eclipse在Java中編輯GridData?
- 6. primefaces:可編輯數據表中的不可編輯列
- 7. 用Javascript編寫的可編輯表格
- 8. Yesod可編輯表格
- 9. 可編輯列表查看
- 10. KnockoutJS可編輯表腳
- 11. WPF可編輯列表視圖與可編輯組合框
- 12. 使用Mindmup可編輯表格使某些列不可編輯
- 13. 用作表編輯器的SWT DateTime控件不會延伸到表格底部
- 14. 可編輯的HTML表格單元格編輯
- 15. 如何使用Javascript或Java編輯可編輯的pdf表單
- 16. jQuery可編輯/可排序列表
- 17. UWP中可編輯的MIDI編輯器
- 18. MoreViewController,編輯,不可編輯的圖標
- 19. 需要「可編輯的下拉列表」
- 20. 使用Drupal的可編輯時間表
- 21. 可編輯的JQuery數據表
- 22. Angularjs中的可編輯列表
- 23. 綁定兒童的可編輯列表
- 24. 嵌入可編輯的電子表格
- 25. 可編輯的Java圖表庫
- 26. 首選項中的可編輯列表
- 27. 在ASP.net MVC可編輯的動態表
- 28. 工作表中不可編輯的NSTextField
- 29. 創建可編輯的新行到表
- 30. 可編輯的jQuery插件列表?
在這種情況下,只有一列可以編輯。它是否正確? – Zoot 2013-09-30 21:11:26