title: SWT draw a table dynamically in a form
body: <p>I have a form where in a section of the form I have an action on the toolbar.
  Running the action should result in drawing an swt table in the form with dynamic columns and rows.</p>
  
  <p>The problem is that the only way I managed to do this is by creating an empty table initially and then passing the table handle to the action which later will fill it up.</p>
  
  <p>If I have the action code to draw the table the form doesn't expand (scroll) to show the whole table.</p>
  
  <p>Is there any way to achieve what I want without creating an initial table?</p>
  
  <p>The code I have using a Composite is like this:
  For creating the composite in the form construction:</p>
  
  <pre><code>    gd = new GridData();
      gd.widthHint = 400;
      gd.heightHint = 200;
  
      tableComposite = new Composite(this.client, SWT.None);
      tableComposite.setLayoutData(gd);
  </code></pre>
  
  <p>In the action code:</p>
  
  <pre><code>        GridData gd = new GridData();
      gd.widthHint = 400;
      gd.heightHint = 200;
  
      if (this.viewer != null) {
          this.viewer.getTable().setRedraw(false);
  
          while (this.viewer.getTable().getColumnCount() &gt; 0) {
              this.viewer.getTable().getColumns()[0].dispose();
          }
          this.viewer.getTable().dispose();
          this.viewer = null;
      }
      this.viewer = new TableViewer(composite, SWT.BORDER
              | SWT.FULL_SELECTION);
      this.viewer.setContentProvider(new FeatureContentProvider());
      this.viewer.setLabelProvider(new FeatureLabelProvider());
      this.viewer.getTable().setLayoutData(gd);
      this.viewer.getTable().setHeaderVisible(true);
      this.viewer.getTable().redraw();
      this.viewer.refresh();
  
      List&lt;String&gt; columnNames = getColumnNamesForTable();
      for (String name : columnNames) {
          TableColumn c = new TableColumn(this.viewer.getTable(), SWT.NONE);
          c.setText(name);
          c.setWidth(100);
      }
  
      this.viewer.getTable().redraw();
      this.viewer.refresh();
  
      this.viewer.setInput(iterations);
      this.composite.layout(true, true);
  </code></pre>
  
  <p>Where composite is parameter passed from the form in the action code. The table seems to be allocated and the space for the composite also but it's no shown.</p>