Project: SWT
Bug 81264 Table fails to setTopIndex after new items are added to the table
Reported: 2004-12-15 13:17:42 | Status: verified fixed

I am working on a table viewer that keeps track of the scroll bar and loads content into the table dynamically as the user scrolls to the end of the table. Items could be added/removed from the table as the user scrolls. To maintain the position of the table, I call setTopIndex at the end of the update. I have created a small testcase to simulate the process. Here's my testcase to demonstrate the problem: public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10,10,200,200); final Table table = new Table(shell, SWT.NONE); table.setBounds(10,10,100,100); for (int i = 0; i < 99; i++) { new TableItem(table, SWT.NONE).setText("item " + i); } table.setTopIndex(20); shell.open(); System.out.println("top visible index: " + table.getTopIndex()); for (int i = 0; i < 5; i++) { new TableItem(table, SWT.NONE).setText("item " + i); } table.setTopIndex(40); System.out.println("top visible index: " + table.getTopIndex()); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } Table.setTopIndex fails to position to the correct table item if new items are added to the table after the shell is opened. The first call to setTopIndex succeeds. The table is correctly positioned at item 20. After adding new table items to the table, calling setTopTable(40) has no effect. Calling getTopIndex continues to return 20. Expected Result: Calling setTopIndex(40) should move table item #40 to the top of the table. Calling getTopIndex after should return 40. If the last 5 items are added before the shell is opened, setTopIndex to 40 will also succeed. The testcase works as expected on Windows.

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