title: How to add a row to a table using swt
body: <p>I am learning swing and have one doubt regarding insertion of row to a table.
  My requirement is such that I have to add a new row by pressing a add button. But I am not able to proceed. please find the code below:</p>
  
  <p>If some one know please help me....</p>
  
  <pre><code>{public class TableShellExample {
  
  
  Display d;
   Shell s;
   TableViewer tableViewer;
   CellEditor cellEditor;
  
   TableShellExample(){
    d = new Display();
    s = new Shell();
    s.setSize(250,250);
    s.setText("Table Shell Example");
  
    GridLayout g1 = new GridLayout();
    g1.numColumns = 3;
    s.setLayout(g1);
    final Table table = new Table(s,SWT.BORDER |SWT.CHECK|SWT.MULTI | SWT.FULL_SELECTION);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 3;
    table.setLayoutData(gd);
    table.setHeaderVisible(true);
  
    TableColumn tc1 = new TableColumn(table, SWT.LEFT);
    TableColumn tc2 = new TableColumn(table,SWT.CENTER);
    TableColumn tc3 = new TableColumn(table,SWT.CENTER);
    tc1.setText("FIRST NAME");
    tc2.setText("LAST NAME");
    tc3.setText("ADDRESS");
    tc1.setWidth(70);
       tc2.setWidth(70);
       tc3.setWidth(80);
    TableItem it1 = new TableItem(table,SWT.NONE);
    it1.setText(new String[]{"aaa","bbb","pune"});
    TableItem it2 = new TableItem(table,SWT.NONE);
    it2.setText(new String[]{"aaa","bbb","pune"});
    TableItem it3 = new TableItem(table,SWT.NONE);
    it3.setText(new String[]{"aaa","bbb","pune"});
  
    //tableViewer = new TableViewer(table);
    //tableViewer.setColumnProperties(tc1);
    //tableViewer.setContentProvider(new IContentProvider());
    //tableViewer.setLabelProvider(new TableLabelProvider());
  
    CellEditor[] editors = new CellEditor[2];
    //editors[0] = new TextCellEditor(table);
    //editors[1] = new TextCellEditor(table);
    //tableViewer.setCellEditors(editors);
    //tableViewer.setCellModifier(new ICellModifier());
  
  
    final Text input = new Text(s, SWT.SINGLE | SWT.BORDER);
       input.setTextLimit(5);
       final Button searchBtn = new Button(s, SWT.BORDER | SWT.PUSH);
       searchBtn.setText("Search");
    searchBtn.addSelectionListener(new SelectionAdapter() {
    public void widgetSelected(SelectionEvent e){
     TableItem[] tia = table.getItems();
     for(int i=0;i&lt;tia.length;i++){
      tia[i].getText();
       //tia[i].setBackground(new Color(d, 129, 178, 127));
      //}
  
  
     }
    }
  
    });
    final Button addButton = new Button(s,SWT.BORDER | SWT.PUSH);
    addButton.setText("Add Row");
    addButton.setToolTipText("for addind a new row");
    addButton.addListener(SWT.Selection, new Listener() {
  
     public void handleEvent(Event arg0) {
      TableEditor te = new TableEditor(table);
      te.grabHorizontal = true;
      te.grabVertical = true;
      te.getItem();
      TableItem ti = table.getItem(0);
      ti.getText();
  
  
     }
    });
    s.open();
       while (!s.isDisposed()) {
         if (!d.readAndDispatch())
           d.sleep();
       }
       d.dispose();
   }
   public Vector rowToAdd() {
    Vector defaultRow = new Vector();
    defaultRow.add("column1");
    defaultRow.add("column1");
    return defaultRow;
    }
  
   public static void main(String[] argv){
    new TableShellExample();
   }
  }
  </code></pre>