by Dinesh Thakur Category: Swing

 

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



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles