import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
public class TableRowSelection {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setSize(480,320);
final Table table = new Table(shell, SWT.MULTI | SWT.BORDER
| SWT.FULL_SELECTION);
table.setLinesVisible(true);
table.setHeaderVisible(true);
String[] titles = { "A", "B", "C" };
for (int i = 0; i < titles.length; i++) {
TableColumn column = new TableColumn(table, SWT.NONE);
column.setText(titles[i]);
}
int count = 10;
for (int i = 0; i < count; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText(0, "a" + i);
item.setText(1, "b" + i * i);
item.setText(2, "c" + i * i * i);
}
for (int i = 0; i < titles.length; i++) {
table.getColumn(i).pack();
}
table.setSize(table.computeSize(SWT.DEFAULT, 200));
final Text text1 = new Text(shell, SWT.BORDER);
GridLayout gl1 = new GridLayout();
gl1.numColumns = 1;
GridData gData = new GridData(GridData.FILL_BOTH);
table.setLayoutData(gData);
gData = new GridData(GridData.FILL_HORIZONTAL);
text1.setLayoutData(gData);
shell.setLayout(gl1);
table.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
TableItem item = table.getItem(table.getSelectionIndex());
text1.setText("");
for (int i = 0; i < table.getColumnCount(); i++)
text1.append(item.getText(i));
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}