More Tutorials| Bioinformatics| Open Source| Photoshop| Questions? | Software Development
 

Create Tree in SWT

SWT allows an advantage of creating a tree. To represent the data in the hierarchical way, the class Tree is used. It provides the hierarchy of items.

Create Tree in SWT

                         

This section illustrates you how to create a tree.

SWT allows an advantage of creating a tree. To represent the data in the hierarchical way, the class Tree is used. It provides the hierarchy of items. 

The constructor of class Tree consists of shell and the style value. The class TreeItem represents the hierarchy of tree items in a tree by adding an item to the tree. Its constructor consists of parent, style value and the index.

The method setText() sets the text specified. 

Here is the code of CreateTree.java

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.widgets.*;

public class CreateTree {    
        Display display;
        Shell shell;
        CreateTree()    {
        display= new Display();
        shell = new Shell(display);
        shell.setSize(230,220);
        shell.setText("Tree");
        shell.setLayout(new FillLayout());

        Tree tree = new Tree(shell, SWT.SINGLE | SWT.BORDER);
        TreeItem item1 = new TreeItem(tree, SWT.NONE, 0);
        item1.setText("Task1");
        TreeItem item1a = new TreeItem(item1, SWT.NONE, 0);
        item1a.setText("Task 1.1");
        TreeItem item1b = new TreeItem(item1, SWT.NONE, 1);
        item1b.setText("Task 1.2");

        TreeItem item2 = new TreeItem(tree, SWT.NONE, 1);
        item2.setText("Task2");
        TreeItem item2a = new TreeItem(item2, SWT.NONE, 0);
        item2a.setText("Task 2.1");
        TreeItem item2a1 = new TreeItem(item2a, SWT.NONE, 0);
        item2a1.setText("Task 2.1.1");
        TreeItem item2a2 = new TreeItem(item2a, SWT.NONE, 1);
        item2a2.setText("Task 2.1.2");
        TreeItem item2b = new TreeItem(item2, SWT.NONE, 1);
        item2b.setText("Task 2.2");
        TreeItem item2c = new TreeItem(item2, SWT.NONE, 2);
        item2c.setText("Task 2.3");

        TreeItem item3 = new TreeItem(tree, SWT.NONE, 2);
        item3.setText("Task3");
        TreeItem item3a = new TreeItem(item3, SWT.NONE, 0);
        item3a.setText("Task 3.1");
        TreeItem item3b = new TreeItem(item3, SWT.NONE, 1);
        item3b.setText("Task 3.2");

        shell.open();
        while(!shell.isDisposed()){
        if(!display.readAndDispatch())
        display.sleep();
            }
            display.dispose();
        }
        public static void main(String[] argv){
          new CreateTree();
        }
}

Output will be displayed as

Download Source Code

                         

» View all related tutorials
Related Tags: c eclipse ide class button io swt get ip widgets order vi widget using cli border this id package rad

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.