title: How do I automatically update Java SWT table cells that already have information?
body: <p>I am trying to update this table automatically with a syncexec.  The code I am pasting is a test code that produces the same symptoms I am experiencing, but instead of live data from an external source, I am using the random number generating utility.  </p>
  
  <p>I have 2 columns.  One column is a place holding number 1-9.  The second column represents live data and will frequently change.  I want that second column to update.</p>
  
  <p>I am currently just adding rows which do indicate live data, but I would like to have only 9 rows total, not 9 added rows ever few milliseconds. I know it's doing this because I am populating the table over and over in my syncexec.  How do I just update the table that I established in the UI, with my syncexec?</p>
  
  <pre><code>import org.eclipse.swt.SWT;
  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;
  import org.eclipse.swt.layout.GridData;
  import org.eclipse.swt.layout.GridLayout;
  import org.eclipse.swt.widgets.Label;
  import org.eclipse.swt.graphics.Point;
  import org.eclipse.swt.graphics.Rectangle;
  import java.util.Random;
  
  public class TableAutoUpdate
  {
  int u = 10;     
  int i;  
  int r;
  int d = 10;
  int c = 1;
  int v = u+1;
  
  boolean a = false;
  
  private Label label; //Must import org.eclipse.swt.widgets.Label; then     declare it in the class to use it.
  private Label status;
  private Display display;
  private Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.CENTER );
  
  public TableAutoUpdate(Display display)
  {
      try
      {
      initUI(display);
      invalidateUiData();
      }
  
      catch (NoClassDefFoundError e)
      {
          status.setText(e.toString());
      }
  }
  
  
  private void initUI(Display display)
  {
      shell.setLayout(new GridLayout(3, false));
      String RegisterLabels[] = new String[u];
      status = new Label(shell, SWT.BORDER); 
      GridData gd2 = new GridData(SWT.FILL, SWT.FILL, true, true);   
      status.setLayoutData(gd2);
      gd2.widthHint = 40;
      gd2.heightHint = 15;
      gd2.horizontalSpan = 3;
  
      Table table = new Table(shell, SWT.BORDER);
      table.setHeaderVisible(true);
      table.setLinesVisible(true);
  
      TableColumn tc1 = new TableColumn(table, SWT.CENTER);
      TableColumn tc2 = new TableColumn(table, SWT.CENTER);
  
  
      tc1.setText("Register Number");
      tc2.setText("Register Value");
  
  
      tc1.setWidth(110);
      tc2.setWidth(110);
  
      int b = 1;
  
      Random randomGen = new Random();
      int randomInt = randomGen.nextInt(32000);
  
      for(i=1; i&lt;u; i++)
      {
      status.setText("Valid numbers");
      TableItem item1 = new TableItem(table, SWT.NONE);
      RegisterLabels[i] = Integer.toString(b);
      item1.setText(new String[] {RegisterLabels[i],     item1.getText(randomInt)});
      b++;
      }
  
  
      shell.setSize(300, 300);
      status.getText();    
      shell.setText("Modbus Tags");
      centerWindow(shell);
      shell.open();   
  
  
      new Thread() 
      {
          @Override
          public void run() 
          {
              for (final int l = 1; l &lt;= l; ) 
              {
              try 
              {
                  Thread.sleep (100);
              } 
              catch (Throwable th) 
              {
  
              }
                  if (display.isDisposed()) return;
                  display.syncExec(new Runnable() 
                  {
                      @Override
                      public void run()
                      {  
  
                              try
                              {
                                  int b = 1;
                                  for (r = 1; r &lt; u; r++)
                                  {
                                      Random randomGen = new Random();
                                      int randomInt =     randomGen.nextInt(32000);
                                      status.setText("Random Number Table     Update");
                                      TableItem item1 = new TableItem(table,     SWT.NONE);
                                      RegisterLabels[r] = Integer.toString(b);
                                      item1.setText(new String[]     {RegisterLabels[r], Integer.toString(randomInt)});
                                      b++;
                                  }
                              }
                              catch (Exception e)
                              {
                                  status.setText("Invalid Number");
                                  try 
                                  {
                                      Thread.sleep (1000);
                                  } 
                                  catch (Throwable th) 
                                  {
  
                                  }
                                  invalidateUiData();
                              }
                          }
                      });
              }
          }
      }.start();
  
  
      while (!shell.isDisposed()) 
      {
          if (!display.readAndDispatch())
              display.sleep();
      }
  }
  
  
  void invalidateUiData()
  {
     status.setText("Unable to numbers.");
  }
  
  private void centerWindow(Shell shell) {
  
      Rectangle bds = shell.getDisplay().getBounds();
  
      Point p = shell.getSize();
  
      int nLeft = (bds.width - p.x) / 2;
      int nTop = (bds.height - p.y) / 2;
  
      shell.setBounds(nLeft, nTop, p.x, p.y);
  }
  
  
  @SuppressWarnings("unused")
  public static void main(String[] args) {
  
      Display display = new Display();
      TableAutoUpdate ex = new TableAutoUpdate(display);
      display.dispose();
  }
  }
  </code></pre>