Reputation: 26617
EDIT: Here's the code based on Max's suggestion
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);
}
}
}
});
I have a JFace TableViewer with a column that is editable (done by implementing EditingSupport
).
I want the user to be able to press the up/down arrows when editing a cell to move to the row above/below it. Here's what I have:
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);
}
}
}
});
This moves the selected row to the next row, but doesn't move the textbox, i.e. after pressing down arrow it looks like this:
How do I set the textbox to the cell in a a particular row?
Upvotes: 2
Views: 2981
Reputation: 2907
Use the method:
org.eclipse.jface.viewers.ColumnViewer.editElement(Object element, int column)
Upvotes: 6