且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在JTree中显示JTable的行为与外观不同

更新时间:2023-12-04 08:46:16

我从以下链接中得出了答案:

I figured this out from the below link:

https://www .daniweb.com/software-development/java/threads/386037/different-height-of-jtree-nodes

本质上,所需要做的就是将行高设置为0,以使叶节点高度可变,这取决于要渲染的组件,而不是固定的(我认为)默认值.

In essence, all that is needed to do is set the row height to 0 to make the leaf node height variable, depending on the component being rendered as opposed to a fixed (I presume) default value.

因此,代码如下所示:

JTree tree = new JTree(root);
tree.setRowHeight(0);
tree.setCellRenderer(new ExampleRenderer());

结果是这样的: