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

Practical 7

Uploaded by

tidew88312
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)
8 views2 pages

Practical 7

Uploaded by

tidew88312
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

import javax.swing.

*;

import javax.swing.tree.DefaultMutableTreeNode;

public class SimpleTreeDemo extends JFrame {

public SimpleTreeDemo() {

super();

DefaultMutableTreeNode root = new DefaultMutableTreeNode("India");

DefaultMutableTreeNode maharashtra = new DefaultMutableTreeNode("Maharashtra");

DefaultMutableTreeNode karnataka = new DefaultMutableTreeNode("Karnataka");

DefaultMutableTreeNode gujarat = new DefaultMutableTreeNode("Gujarat");

root.add(maharashtra);

root.add(karnataka);

root.add(gujarat);

maharashtra.add(new DefaultMutableTreeNode("Mumbai"));

maharashtra.add(new DefaultMutableTreeNode("Pune"));

karnataka.add(new DefaultMutableTreeNode("Bangalore"));

karnataka.add(new DefaultMutableTreeNode("Mysore"));

gujarat.add(new DefaultMutableTreeNode("Ahmedabad"));

gujarat.add(new DefaultMutableTreeNode("Surat"));

JTree tree = new JTree(root);

JScrollPane treeScrollPane = new JScrollPane(tree);

add(treeScrollPane);

setSize(300, 300);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

public static void main(String[] args) {

new SimpleTreeDemo();

}}

You might also like