Simple Tree : Tree « SWT JFace Eclipse « Java






Simple Tree

Simple Tree
/******************************************************************************
 * All Right Reserved. 
 * Copyright (c) 1998, 2004 Jackwind Li Guojie
 * 
 * Created on Mar 10, 2004 8:08:56 PM by JACK
 * $Id$
 * 
 *****************************************************************************/



import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
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 SWTSimpleTree {
  Display display = new Display();
  Shell shell = new Shell(display);
  
  Tree tree;

  public SWTSimpleTree() {
    shell.setLayout(new GridLayout());
    
    tree = new Tree(shell, SWT.BORDER);
    
    tree.setLayoutData(new GridData(GridData.FILL_BOTH));
    
    TreeItem item = new TreeItem(tree, SWT.NULL);
    item.setText("ITEM");
    
    TreeItem item2 = new TreeItem(item, SWT.NULL);
    item2.setText("ITEM2");
    
    TreeItem item3 = new TreeItem(item2, SWT.NULL);
    item3.setText("ITEM3");
    
    System.out.println("item: " + item.getParent() + ", " + item.getParentItem());
    System.out.println("item2: " + item2.getParent() + ", " + item2.getParentItem());
    
    System.out.println(tree.getItemCount());
    System.out.println(tree.getItems().length);
    
    shell.setSize(300, 200);
    shell.open();
    //textUser.forceFocus();

    // Set up the event loop.
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        // If no more entries in event queue
        display.sleep();
      }
    }

    display.dispose();
  }

  private void init() {

  }

  public static void main(String[] args) {
    new SWTSimpleTree();
  }
}



           
       








Related examples in the same category

1.SWT Tree With Multi columnsSWT Tree With Multi columns
2.Detect Mouse Down In SWT Tree ItemDetect Mouse Down In SWT Tree Item
3.Limit selection to items that match a pattern in SWT TreeLimit selection to items that match a pattern in SWT Tree
4.SWT Tree Simple DemoSWT Tree Simple Demo
5.Category Tree
6.Bookmark OrganizerBookmark Organizer
7.Displays a single-selection tree, a multi-selection tree, and a checkbox treeDisplays a single-selection tree, a multi-selection tree, and a checkbox tree
8.Demonstrates TableTreeDemonstrates TableTree
9.Demonstrates TreeEditorDemonstrates TreeEditor
10.Tree ExampleTree Example
11.Tree Example 2
12.Demonstrates CheckboxTreeViewer
13.Demonstrates TreeViewerDemonstrates TreeViewer
14.SWT Tree SWT Tree
15.SWT Tree Composite
16.Print selected items in a SWT treePrint selected items in a SWT tree
17.Insert a SWT tree item (at an index)Insert a SWT tree item (at an index)
18.Detect a selection or check event in a tree (SWT.CHECK)Detect a selection or check event in a tree (SWT.CHECK)
19.Create a SWT tree (lazy)Create a SWT tree (lazy)
20.Create a treeCreate a tree