Bug 75268 snippet 2
I noticed that if I wanted to replace the static creation of the table items and create it dynamically with a "for" loop, that a "widget disposed" type exception is thrown from line "items[i].dispose();" at line 541 of snippet 2 located under "inserting a row in a table" if clicking the second column to perform a sort. I am wondering if there is a reference issue in the Table. If you replace the static creation of the TableItems with the dynamic creation used in a "for" loop you will see that the exception is thrown. Replace: TableItem item = new TableItem(table, SWT.NONE); item.setText(new String[] {"a", "6"}); item = new TableItem(table, SWT.NONE); item.setText(new String[] {"d", "1"}); item = new TableItem(table, SWT.NONE); item.setText(new String[] {"a", "5"}); item = new TableItem(table, SWT.NONE); item.setText(new String[] {"a", "4"}); item = new TableItem(table, SWT.NONE); item.setText(new String[] {"b", "3"}); item = new TableItem(table, SWT.NONE); item.setText(new String[] {"c", "2"}); with: for(int k = 12; k > 0; k--) { TableItem item = new TableItem(table, SWT.NONE); item.setText(new String[] {"a", String.valueOf(k)}); } then click on column 2 to sort the numbers.
examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet2.java
}
    });
    column2.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            
            TableItem[] items = table.getItems();
            Collator collator = Collator.getInstance(Locale.getDefault());
            for (int i = 1; i < items.length; i++) {
                String value1 = items[i].getText(1);
                for (int j = 0; j < i; j++){
                    String value2 = items[j].getText(1);
                    if (collator.compare(value1, value2) < 0) {
                        String[] values = {items[i].getText(0), items[i].getText(1)};
                        items[i].dispose();
                        TableItem item = new TableItem(table, SWT.NONE, j);
                        item.setText(values);
                        break;
                    }
                }
            }
        }
    });
    shell.open ();
    while (!shell.isDisposed ()) {
        if (!display.readAndDispatch ()) display.sleep ();
    }
    display.dispose ();
}
}