如何向 JTree 添加间隙
我的问题是
我正在尝试创建一个并排显示两棵树的组件。这两棵树通常非常相似,但可能有一两个差异。如果存在差异,即一个分支中有一个分支,但另一个分支没有,我希望没有分支的树为它以及每个丢失的子节点显示一个空白空间。
因此,它可能看起来像
left tree right tree ------------ ------------- + Root + Root | | --Child A --Child A | | --Child B | | | --Child C --Child C
使用自定义渲染器删除那些应该是间隙的行的文本和图标相对直接。然而,这仍然留下了连接孩子和父母垂直线的水平线。这是我的问题。
left tree right tree ------------ ------------- + Root + Root | | --Child A --Child A | | --Child B -- <--I want to remove this | | --Child C --Child C
在这个简单的例子中,它可能是可以承受的,但是当缺失的分支也有子节点时,我最终会得到很多连接间隙的小线。
我认为一个潜在的替代方案是为每棵树创建一个单列 JTreeTable 并空白掉缺失分支的单元格。尽管这意味着垂直线的一部分也会丢失。
任何帮助、想法或评论都将非常感激。谢谢。
my problem is this
I'm trying create a component that displays two tree side by side. The two trees will generally be very similar but will probably have one or two differences. Where there is a difference, ie a branch in one but not in the other, I would like the tree without the branch to show an empty space for it, and for each of its missing children too.
So it might look something like
left tree right tree ------------ ------------- + Root + Root | | --Child A --Child A | | --Child B | | | --Child C --Child C
Its relatively straight forward to remove the text and icon for those rows that should be gaps using a custom renderer. However, this still leaves the horizontal line that connects a child to the parents vertical line. And this is my problem.
left tree right tree ------------ ------------- + Root + Root | | --Child A --Child A | | --Child B -- <--I want to remove this | | --Child C --Child C
It's maybe bareable in this simple example but when the missing branch has children too I end up with lots of small lines connecting gaps.
A potential alternative I think is to create a one column JTreeTable for each tree and blank out the cells for the missing branches. Although this will mean that a portion of the vertical line will also be lost.
Any help, ideas or comments will be very much appriciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请考虑以下内容:
使用示例:
Consider the following:
Usage example: