Hi,
How can I load a Jtree directory with children on expanding the node of that directory.
I have developed the following SSCCE. Please explain in its context.
My specific question is, when you execute the code given here, you can see the file bb.1 inside the directory bb.
bb.1 is a dummy which I used while creating the Jtree. When I expand bb, instead of the leaf bb.1 , I want to display some other file name, say qq.1 or jj.1.
What should I do?
Hope my question is clear.
Java Code:
//FileTreeFrame.java
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
public class FileTreeFrame extends JFrame {
  private JTree fileTree;
 
  private FileSystemModel fileSystemModel;
 
 
  public FileTreeFrame(String abc) {
    super("JTree FileSystem Viewer");
   
    // Build up your data
    List rootChildren = new ArrayList();
    rootChildren.add( new MyNode("aa") );
   
    List bbChildren = new ArrayList();
    bbChildren.add( new MyNode("bb.1") );
    rootChildren.add( new MyNode("bb", bbChildren) );
   
    rootChildren.add( new MyNode("cc") );
   
    MyNode rootNode = new MyNode("root", rootChildren);
   
    fileTree = new JTree(new FileSystemModel(new MyTreeNode(rootNode)));
    
    fileTree.setRootVisible(false);
    fileTree.setShowsRootHandles(true);
    getContentPane().add(fileTree);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(640, 480);
    setVisible(true);
  }
 
 
 
  public static void main(String args[]) {
    new FileTreeFrame("");
  }
}

class FileSystemModel extends DefaultTreeModel {
    
    public FileSystemModel(DefaultMutableTreeNode node) {
          super(node);
    }
    
    public boolean isLeaf(Object node) {
          MyTreeNode treeNode = (MyTreeNode)node;
          return !((MyNode)treeNode.getUserObject()).hasChildren();
    }
}
=======================================================
//MyNode.java
import java.util.List;

public class MyNode {
      
      private String name;
      private List children;
      
      public MyNode(String name) {
            this.name = name;
      }
      public MyNode(String name, List children) {
            this.name = name;
            this.children = children;
      }

      public boolean hasChildren() {
            return children!=null && children.size()>0;
      }
      
      public String toString() {
            return name;
      }
      
      public List getChildren() {
            return children;
      }
}


=========================================================

//MyTreeNode.java
import java.util.Iterator;

import javax.swing.tree.DefaultMutableTreeNode;

public class MyTreeNode extends DefaultMutableTreeNode {

    public MyTreeNode(MyNode node) {
        super(node);
        addSubNodes();
    }

    private void addSubNodes() {
          MyNode content = (MyNode)getUserObject();
          if (content!=null && content.hasChildren()) {
                for (Iterator it = content.getChildren().iterator(); it.hasNext();) {
                      add( new MyTreeNode((MyNode)it.next()) );
                }
          }
    }
   
   
}
Please help with a solution.
Regards,
Anees