gwt
StaticTree Example
With this example we are going to demonstrate how to create a static Tree, using the Google Web Toolkit, that is an open source set of tools that allows web developers to create and maintain complex JavaScript front-end applications in Java. A Tree is a standard hierarchical tree widget. The tree contains a hierarchy of TreeItems that the user can open, close, and select. In short, to create a static Tree we have followed the steps below:
- The
StaticTreeExampleclass implements thecom.google.gwt.core.client.EntryPointinterface to allow the class to act as a module entry point. It overrides itsonModuleLoad()method. - We create a new Tree object and add TreeItem objects to the Tree object.
- We add the
Treeto theRootPanel, that is the panel to which all other widgets must ultimately be added.
Let’s take a look at the code snippet that follows:
package com.javacodegeeks.snippets.enterprise;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Tree;
import com.google.gwt.user.client.ui.TreeItem;
public class StaticTreeExample implements EntryPoint {
@Override
public void onModuleLoad() {
// Create new Tree object
Tree tree = new Tree();
// Create new tree Item object
TreeItem Item0 = new TreeItem("Item 0");
// Add Items to Item0
Item0.addItem("Item 0.0");
Item0.addItem("Item 0.1");
Item0.addItem("Item 0.2");
// Create new tree object
TreeItem Item03 = new TreeItem("Item 0.3");
// Add Items to Item 0.3
Item03.addItem("Item 0.3.0");
Item03.addItem("Item 0.3.1");
Item03.addItem(new CheckBox("Item 0.3.2"));
// Add Item 0.3 to Item 0
Item0.addItem(Item03);
// Create new Item and add TreeItems
TreeItem Item1 = new TreeItem("Item 1");
Item1.addItem("Item 1.0");
Item1.addItem("Item 1.1");
Item1.addItem("Item 1.2");
Item1.addItem("Item 1.3");
// Add TreeItems to tree
tree.addItem(Item0);
tree.addItem(Item1);
// Add tree to RootPanel
RootPanel.get().add(tree);
}
}
This was an example of how to create a static Tree using the Google Web Toolkit.



