FTP JTree of Directory and Files
I'm currently developing an application that will allow people to download the files from the online FTP repository, I have it connecting perfectly with Apache Commons, My only trouble is making a JTable out of it.
I know how to create a JTree, My problem is adding the nodes when th开发者_C百科ey are called (Someone presses the plus icon, Load files in sub directory)
Also determining whether they are leafs... I'm sorry, I'm so lost at the moment!
If it were me, i'd remove the plus button, and just load sub directories when you get tree will expand events.
So What you could do, is populate the top level node, with a Stub node under it, and show the tree with the top level node, non-expanded. When the user expands it, you will get the tree will expand event. Look at the child, and see if it's a Stub node. If it is remove it, and use apache commons to load the children, populating each one, and each one with it's own stub node.
What is a stub node? Just a node that somehow tells you that this node is a placeholder. It means that you haven't tried to load children yet. Most likely this Node class will be a special class called StubNode or something. Of course you only need to add Stub nodes to directories, not files, as you won't be expanding files.
http://www.java2s.com/Tutorial/Java/0240__Swing/TreeWillExpandListener.htm
精彩评论