0% found this document useful (0 votes)
44 views3 pages

Practical No

This Java program demonstrates a JTree with three nodes (A, B, C) and subnodes. The program creates DefaultMutableTreeNode objects to represent the nodes and subnodes, adds the nodes and subnodes to the tree, displays the tree in a JScrollPane, and sets the frame size and close operation.

Uploaded by

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

Practical No

This Java program demonstrates a JTree with three nodes (A, B, C) and subnodes. The program creates DefaultMutableTreeNode objects to represent the nodes and subnodes, adds the nodes and subnodes to the tree, displays the tree in a JScrollPane, and sets the frame size and close operation.

Uploaded by

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

TYBSc(IT)-Sem V Advanced Java Roll No:492

PRACTICAL NO:04

AIM: Write a program to demonstrate JTree with three nodes & subnodes.

CODE:

import java.awt.*;

import javax.swing.tree.*;

import javax.swing.*;

public class TreeDemo extends JFrame

JTree tr;

DefaultMutableTreeNode A;

DefaultMutableTreeNode B,C,D;

DefaultMutableTreeNode E,F,G,H,I;

DefaultMutableTreeNode J ;

Container cr;

JScrollPane scroll;

public TreeDemo()
TYBSc(IT)-Sem V Advanced Java Roll No:492

super("Tree Example ");

cr=getContentPane();

A=new DefaultMutableTreeNode("A");

B=new DefaultMutableTreeNode("B");

C=new DefaultMutableTreeNode("C");

D=new DefaultMutableTreeNode("D");

E=new DefaultMutableTreeNode("E");

F=new DefaultMutableTreeNode("F");

G=new DefaultMutableTreeNode("G");

H=new DefaultMutableTreeNode("H");

I=new DefaultMutableTreeNode("I");

J=new DefaultMutableTreeNode("J");

tr=new JTree(A);

tr.setShowsRootHandles(true);

scroll=new JScrollPane(tr);

cr.add(scroll);

A.add(B);

A.add(C);

A.add(D);

B.add(E);
TYBSc(IT)-Sem V Advanced Java Roll No:492

B.add(F);

C.add(G);

C.add(H);

D.add(I);

I.add(J);

setVisible(true);

setSize(400,500);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

public static void main(String args[])

new TreeDemo();

You might also like