0% found this document useful (0 votes)
23 views2 pages

Practical 07

The document shows how to create a JTree in Java to display hierarchical data. It creates a root node for India and child nodes for states. Nodes are then added to display cities in different states to build the tree structure.

Uploaded by

Bhushan Bhoye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Practical 07

The document shows how to create a JTree in Java to display hierarchical data. It creates a root node for India and child nodes for states. Nodes are then added to display cities in different states to build the tree structure.

Uploaded by

Bhushan Bhoye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Practical No : 07

import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;

public class JTreeDemo


{
public static void main(String[] args) {

JFrame JFrameMain = new JFrame();


JFrameMain.setVisible(true);
JFrameMain.setSize(400,400);

DefaultMutableTreeNode rootNode = new


DefaultMutableTreeNode("India");

DefaultMutableTreeNode maharashtraNode = new


DefaultMutableTreeNode("Maharashtra");
DefaultMutableTreeNode gujrathNode = new
DefaultMutableTreeNode("Gujrath");
rootNode.add(maharashtraNode);
rootNode.add(gujrathNode);

DefaultMutableTreeNode mumbaiSubNode = new


DefaultMutableTreeNode("Mumbai");
DefaultMutableTreeNode puneSubNode = new
DefaultMutableTreeNode("Pune");
DefaultMutableTreeNode nashikSubNode = new
DefaultMutableTreeNode("Nashik");
DefaultMutableTreeNode nagpurSubNode = new
DefaultMutableTreeNode("Nagpur");

maharashtraNode.add(mumbaiSubNode);
maharashtraNode.add(puneSubNode);
maharashtraNode.add(nashikSubNode);
maharashtraNode.add(nagpurSubNode);

JTree tree = new JTree(rootNode);


JFrameMain.add(tree);
}

Output :

You might also like