Mega Code Archive

 
Categories / Java by API / Org Eclipse Swt Custom
 

New TableTree(Shell parent, int style)

import org.eclipse.swt.SWT; import org.eclipse.swt.custom.TableTree; import org.eclipse.swt.custom.TableTreeItem; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; public class MainClass {   public static void main(String[] a) {          final Display d = new Display();     final Shell shell = new Shell(d);     shell.setSize(250, 200);               shell.setLayout(new FillLayout());     TableTree tableTree = new TableTree(shell, SWT.NONE);     Table table = tableTree.getTable();     table.setHeaderVisible(true);     table.setLinesVisible(false);     for (int i = 0; i < 3; i++) {       new TableColumn(table, SWT.LEFT).setText("Column " + (i + 1));     }     for (int i = 0; i < 3; i++) {       TableTreeItem parent = new TableTreeItem(tableTree, SWT.NONE);       parent.setText(0, "Parent " + (i + 1));       parent.setText(1, "Data");       parent.setText(2, "More data");       for (int j = 0; j < 3; j++) {         TableTreeItem child = new TableTreeItem(parent, SWT.NONE);         child.setText(0, "Child " + (j + 1));         child.setText(1, "Some child data");         child.setText(2, "More child data");       }       parent.setExpanded(true);     }     // Pack the columns     TableColumn[] columns = table.getColumns();     for (int i = 0, n = columns.length; i < n; i++) {       columns[i].pack();     }                    shell.open();     while (!shell.isDisposed()) {       if (!d.readAndDispatch())         d.sleep();     }     d.dispose();   } }