编辑:这是基于 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);
}
}
}
});
这会将选定的行移动到下一行,但不会移动文本框,即按下向下箭头后,它看起来像这样:
如何将文本框设置为特定行中的单元格?