/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html */ import org.eclipse.swt.SWT; import org.eclipse.swt.custom.TableCursor; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; public class Snippet0096 { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Table table = new Table(shell, SWT.NONE); table.setLinesVisible(true); 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 < 10; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(new String[] { "col1", "col2", "col3" }); } final TableCursor cursor = new TableCursor(table, SWT.NONE); cursor.setSelection(0, 0); cursor.addListener(SWT.KeyDown, new Listener() { public void handleEvent(Event event) { if (event.character != '\r') return; int numColumns = table.getColumnCount(); int newColumn = cursor.getColumn() + 1; int newRow = table.indexOf(cursor.getRow()); if (newColumn == numColumns) { newColumn = 0; newRow++; } if (newRow == table.getItemCount()) { newRow = 0; } cursor.setSelection(newRow, newColumn); } }); column1.pack(); column2.pack(); column3.pack(); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }