Project: SWT
Bug 309269 [Widgets] Table selection event does not return a correct table item
Reported: 2010-04-15 04:08:01 | Status: resolved fixed

Build Identifier: M20090211-1700 Here's a snippet: import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; 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 TableItemTest { static Table table = null; public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); int style = SWT.CHECK | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION; table = new Table(shell, style); final GridData gridData = new GridData(0, 0, false, false); gridData.horizontalSpan = 3; gridData.heightHint = 120; table.setLayoutData(gridData); table.setHeaderVisible(true); TableColumn column = new TableColumn(table, SWT.CENTER); column.setWidth(60); column = new TableColumn(table, SWT.LEFT); column.setWidth(80); column = new TableColumn(table, SWT.LEFT); column.setWidth(300); column = new TableColumn(table, SWT.LEFT); column.setWidth(80); for (int i = 0; i < 5; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(new String[] { String.valueOf(i), "XXXXXX" }); } table.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { TableItem item = (TableItem) event.item; int index = table.indexOf(item); System.out.println(index); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } } the printed index is not correct Reproducible: Always Steps to Reproduce: using the provided snippet can easily reproduce this problem

Files changed in fix:
bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Table.java bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree.java