Table: addListener(int type, Listener lis) : Table « org.eclipse.swt.widgets « Java by API






Table: addListener(int type, Listener lis)

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
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 MainClass {

  public static void main(String[] a) {
    Display display = new Display();
    Shell shell = new Shell(display);
  shell.setLayout(new FillLayout());
    
    // Create a table and column
    final Table table = new Table(shell, SWT.VIRTUAL);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    TableColumn tc = new TableColumn(table, SWT.NONE);
    tc.setText("Virtual Value");
    tc.setWidth(400);

    // Tell the table how many items it has
    table.setItemCount(100);
    
    // Provide the callback handler--this handler
    // is invoked when the table needs new rows
    table.addListener(SWT.SetData, new Listener() {
      public void handleEvent(Event event) {
        TableItem item = (TableItem) event.item;
        item.setText("data");
      }
    });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
}

           
       








Related examples in the same category

1.new Table(Composite parent, int style)
2.new Table(s, SWT.BORDER | SWT.CHECK | SWT.MULTI | SWT.FULL_SELECTION)
3.Table: getColumnCount()
4.Table: getItem(Point p)
5.Table: setHeaderVisible(boolean visible)
6.Table: setLinesVisible(boolean vi)