import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridLayout; 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; public class Tabelle { public static void main(String[] args) { new Tabelle().init(); } private void init() { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Tabellenbeispiel"); shell.setLayout(new GridLayout()); Table table = new Table(shell, SWT.BORDER | SWT.MULTI); table.setToolTipText("Eine Tabelle"); table.setLinesVisible(true); table.setHeaderVisible(true); String[] colNames = { "Spalte 1", "Spalte 2", "Spalte 3", "Spalte 4" }; TableColumn[] cols = new TableColumn[colNames.length]; int[] order = new int[colNames.length]; for (int i = 0; i < colNames.length; i++) { TableColumn tc = new TableColumn(table, SWT.BORDER); tc.setText(colNames[i]); tc.pack(); tc.setMoveable(true); cols[i] = tc; order[i] = i; } for (int k = 0; k < 15; k++) { TableItem item = new TableItem(table, SWT.BORDER); for (int i = 0; i < colNames.length; i++) { item.setText(i, new Integer(k + 1).toString() + "/" + new Integer(i + 1).toString()); } } Button button = new Button(shell, SWT.PUSH); button.setText("Zur\u00FCcksetzen"); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (cols.length > 0) { table.setColumnOrder(order); } } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } }