/**
*
*/
package de.tutorials;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
/**
* @author Thomas.Darimont
*
*/
public class SWTTabTableNavigationExample {
/**
* @param args
*/
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new RowLayout());
final Table table = new Table(shell, SWT.BORDER | SWT.MULTI
| SWT.FULL_SELECTION);
table.setLinesVisible(true);
final int rowCount = 10;
table.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e) {
int currentSelectionIndex = table.getSelectionIndex();
switch (e.detail) {
case SWT.TRAVERSE_TAB_NEXT:
table.setSelection((currentSelectionIndex + 1) % rowCount);
e.doit = false;
break;
case SWT.TRAVERSE_TAB_PREVIOUS:
int index = currentSelectionIndex - 1;
if (index < 0) {
index = rowCount - 1;
}
table.setSelection(index);
e.doit = false;
break;
}
}
});
TableColumn column1 = new TableColumn(table, SWT.NONE);
TableColumn column2 = new TableColumn(table, SWT.NONE);
TableColumn column3 = new TableColumn(table, SWT.NONE);
for (int i = 0; i < rowCount; i++) {
TableItem tableItem = new TableItem(table, SWT.NONE);
tableItem.setText(new String[] { "a" + i, "b" + i, "c" + i });
}
column1.pack();
column2.pack();
column3.pack();
Button button = new Button(shell, SWT.PUSH);
button.setText("button");
shell.pack();
shell.setText("SWTTabTableNavigationExample");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}