TableViewer viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.VIRTUAL | SWT.FULL_SELECTION); List<String> labels = .... for (int i = 0; i < labels.length; i++) { TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE); column.getColumn().setText(labels[i]); column.getColumn().setResizable(true); column.getColumn().setMoveable(true); } Table table = viewer.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true);
Table table = viewer.getTable(); for( int i = 0; i < table.getColumnCount(); i++ ) table.getColumn(i).pack();
public void inputChanged(final Viewer viewer, Object oldInput, final Object newInput) { PlatformUI.getWorkbench().getDisplay().asyncExec( new Runnable(){ @Override public void run() { if( viewer.getControl().isDisposed() ) return; // insert elements into the view // now refresh the view (this should be not necessary) viewer.refresh(); // get the table of this viewer Table table = viewer.getTable(); // iterate on each column and pack it for( int i = 0; i < table.getColumnCount(); i++ ) table.getColumn(i).pack(); } });
public synchronized void run() { List<T> loadedElements = // load elements this.contentProvider.inputChanged( this.viewer, loadedElements, loadedElements ); try { this.sleep(2000); PlatformUI.getWorkbench().getDisplay().asyncExec( new Runnable(){ @Override public void run() { // here pack the columns as above } }); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }