by Dinesh Thakur

 

import java.awt.*;

import java.util.*;
import javax.swing.*;
import javax.swing.tree.*;
public class JavaExampleTreeDataInJApplet extends JApplet
{
    Hashtable HshTbl = new Hashtable();
    Hashtable SbHshTblOne = new Hashtable();
    Hashtable SbHshTblTwo = new Hashtable();
    String[] Strngs = new String[]{"Item One","Item Two","Item Three","Item Four","Item Five"};
    public void init()
    {
        Container Cntnr = getContentPane();
        HshTbl.put("Items",Strngs);
        HshTbl.put("Subitems",SbHshTblOne);
        SbHshTblOne.put("Items",Strngs);
        SbHshTblOne.put("Item One", new Integer(1));
        SbHshTblOne.put("Item Two", new Integer(2));
        SbHshTblOne.put("Item Three", new Integer(3));
        SbHshTblTwo.put("Items with subitems",SbHshTblTwo);
        SbHshTblTwo.put("Still More SubItems",Strngs);
        SbHshTblTwo.put("Item One", new Integer(1));
        SbHshTblTwo.put("Item Two", new Integer(2));
        SbHshTblTwo.put("Item Three", new Integer(3));
        JTree HshTree = new JTree(HshTbl);
        JScrollPane HshPn = new JScrollPane(HshTree);
        HshTree.expandPath(new TreePath(HshTree.getModel().getRoot()));   
        Cntnr.add(HshPn);
    }
}
/*<APPLET CODE=JavaExampleTreeDataInJApplet.class WIDTH=350 HEIGHT=280></APPLET>*/
Tree Data Structure in Java Example