编辑:以下是基于Max建议的代码
editor.getControl().addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
Table table = viewer.getTable();
int currentIndex = table.getSelectionIndex();
if (e.keyCode == SWT.ARROW_DOWN) {
if (currentIndex != table.getItemCount() - 1) {
table.setSelection(currentIndex+1);
IStructuredSelection sel = (IStructuredSelection) viewer.getSelection();
Object rowObj = sel.getFirstElement();
viewer.editElement(rowObj, columnIndex);
}
}
}
});
我有一个JFace TableViewer,其列可编辑(通过实现EditingSupport
完成)。
我希望用户能够在编辑单元格时按向上/向下箭头移动到其上方/下方的行。这就是我所拥有的:
final TextCellEditor editor = new TextCellEditor(viewer.getTable());
editor.getControl().addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.keyCode == SWT.ARROW_DOWN) {
Table table = viewer.getTable();
int currentIndex = table.getSelectionIndex();
if (currentIndex != table.getItemCount() - 1) {
table.setSelection(currentIndex+1);
}
}
}
});
这会将所选行移动到下一行,但不会移动文本框,即在按下箭头后它看起来像这样:
如何将文本框设置为特定行中的单元格?
答案 0 :(得分:6)
使用方法:
org.eclipse.jface.viewers.ColumnViewer.editElement(Object element, int column)