Create Three Level Tree : Tree « SWT « Java Tutorial






Create Three Level Tree
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

public class TreeThreeLevel {

  public static void main(String[] args) {

    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    
    final Tree tree = new Tree(shell, SWT.BORDER);
    for (int i = 0; i < 3; i++) {
      TreeItem item = new TreeItem(tree, SWT.NONE);
      item.setText("item " + i);
      for (int j = 0; j < 3; j++) {
        TreeItem subItem = new TreeItem(item, SWT.NONE);
        subItem.setText("item " + i + " " + j);
        for (int k = 0; k < 3; k++) {
          TreeItem subsubItem = new TreeItem(subItem, SWT.NONE);
          subsubItem.setText("item " + i + " " + j + " " + k);
        }
      }
    }

    shell.setSize(400, 400);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
}








17.57.Tree
17.57.1.Trees
17.57.2.Create a TreeCreate a Tree
17.57.3.Populate tree lazilyPopulate tree lazily
17.57.4.Create Three Level TreeCreate Three Level Tree
17.57.5.Insert TreeItem to TreeInsert TreeItem to Tree
17.57.6.Add checkbox mark to the tree nodeAdd checkbox mark to the tree node
17.57.7.A multiselection treeA multiselection tree
17.57.8.A single-selection treeA single-selection tree