目录和文件的 FTP JTree
我目前正在开发一个应用程序,允许人们从在线 FTP 存储库下载文件,我让它与 Apache Commons 完美连接,我唯一的麻烦是用它制作 JTable。
我知道如何创建 JTree,我的问题是在调用节点时添加节点(有人按加号图标,在子目录中加载文件)
还要确定它们是否是叶子...对不起,我迷路了眼下!
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 they 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果是我,我会删除加号按钮,并在获取树将展开事件时加载子目录。
因此,您可以做的是填充顶级节点,并在其下方添加一个存根节点,并显示具有顶级节点(未展开)的树。当用户展开它时,您将收到树将展开的事件。查看子节点,看看它是否是一个 Stub 节点。如果它被删除,并使用 apache commons 加载子节点,填充每个子节点,并且每个子节点都有自己的存根节点。
什么是存根节点?只是一个以某种方式告诉您该节点是占位符的节点。这意味着您还没有尝试加载子项。这个 Node 类很可能是一个名为 StubNode 之类的特殊类。当然,您只需将存根节点添加到目录,而不是文件,因为您不会扩展文件。
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.