Displaying System Files in JTree

In this
section, you will learn to create a JTree that displays system files. The java.util.properties package
represents a
persistent set of properties for displaying the system files in a tree.
Description of the program:
This program teaches to display all system files in a tree on the
frame. First of all you need a frame that displays the system files
in a tree. The getProperties() displays the current
values of system and returns the system objects. Create a tree using JTree()
constructor with system property. The setLookAndFeel() method sets look
and feel of the generated tree. This method takes a string argument ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel")
that displays the formatting design of the tree. If you want to display the root
node, you must be use setRootVisibles(true) method.
getProperties():
This method displays the current values of system and searchs the property
with the specified key in the properties list.
Here is the code of this program:
import javax.swing.*;
import javax.swing.event.*;
import java.util.Properties;
import javax.swing.JTree.*;
public class FileDirectoryTree{
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
JFrame fm = new JFrame("System file properties of tree ");
Properties p = System.getProperties();
JTree tree = new JTree(p);
tree.setRootVisible(true);
JScrollPane scrollpane = new JScrollPane(tree);
fm.getContentPane().add(scrollpane, "Center");
fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setSize(450,400);
fm.setVisible(true);
}
catch (Exception e) {}
}
}
|
Download this
program.
Output this program:


|