Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

what program should i write (using jtree etc..) to display dir-structures of my comp  RSS feed

Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

sir i want to build a FileDialog for my degree project.i do not want to use html "input type = file" facality.
<P> if it is possible then give me the source code for that.
<P>i'm sending you the source code of a example from "Complete Reference"(chepter 26).this example displaying dummy structure please make changes in it so that it display my system Directory structure.
<p>thank you very much
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
<applet code="JTreeEvents" width=400 height=200>

public class JTreeEvents extends JApplet {
JTree tree;
JTextField jtf;
public void init() {
// Get content pane
Container contentPane = getContentPane();
// Set layout manager
contentPane.setLayout(new BorderLayout());
// Create top node of tree
DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options");
TreeNode te = (javax.swing.tree.TreeNode)"tree";
// Create subtree of "A"
DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");
DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1");
DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2");
// Create subtree of "B"
DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1");
DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("B2");
DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3");
// Create tree
tree = new JTree(te);
// Add tree to a scroll pane
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(tree, v, h);
// Add scroll pane to the content pane
contentPane.add(jsp, BorderLayout.CENTER);
// Add text field to applet
jtf = new JTextField("", 20);
contentPane.add(jtf, BorderLayout.SOUTH);
// Anonymous inner class to handle mouse clicks
tree.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent me) {
void doMouseClicked(MouseEvent me) {
TreePath tp = tree.getPathForLocation(me.getX(), me.getY());
if(tp != null)

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!