Java:嵌套树结构
我正在寻找一种在 GUI 中创建嵌套树结构的方法。我有几个“盒子”,里面装有物品。我希望这些框在单击时折叠但展开,就像在侧边栏上导航文件夹的方式一样。我考虑的第一种方法是将“盒子”视为 JList,每个盒子中的项目存储在嵌套的 JList 中。这似乎是一种非常复杂且糟糕的方法。它还可以防止盒子在没有对动作监听器进行大量修改的情况下折叠。我希望有人可能知道一个可能用于显示此处可能使用的文件导航的 API。
I am looking for a way to create a nested tree structure in my GUI. I have a few "boxes" that have items in them. I would like the boxes to be collapsed but expanded when clicked on, like the way folders are navigated on the sidebar. The first way I considered was treating the "boxes" as JList, with the items in each box stored in a nested JList. This seems like a very complicated and poor way of doing it. It also prevents the boxes from being collapsible without extensive modifications to the actionlistener. I was hoping someone might know of an API perhaps for displaying file navigation that might be used here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您正在寻找 JTree 。有一个使用 JTree 的教程。
It sounds like you are looking for JTree. There is a tutorial on using JTree.
也许您正在寻找类似这个的东西。
Perhaps you are looking for something like this.