Java Practical7
Java Practical7
import javax.swing.tree.*;
root.add(child1);
root.add(child2);
root.add(child3);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new JScrollPane(tree));
frame.setSize(300, 300);
frame.setVisible(true);
Output:
Q2. Write a program code to generate the following output
import javax.swing.*;
import javax.swing.tree.*;
root.add(child1);
root.add(child6);
child1.add(child2);
child1.add(child3);
child1.add(child4);
child1.add(child5);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new JScrollPane(tree));
frame.setSize(300, 300);
frame.setVisible(true);
Output:
Exercise:
Q1. Write a Jtree program to show root directory and its subdirectory and its
subFolders of Your System.
import javax.swing.*;
import javax.swing.tree.*;
root.add(child0);
child0.add(child1);
child0.add(child2);
child0.add(child3);
child3.add(child4);
child3.add(child5);
root.add(child6);
child6.add(child7);
child7.add(child8);
child7.add(child9);
child6.add(child10);
root.add(child11);
child11.add(child12);
child12.add(child13);
child12.add(child14);
child11.add(child15);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new
JScrollPane(tree));
frame.setSize(300, 300);
frame.setVisible(true); }}
Output: