JTree 节点名称/组名称不可见
我编写了一个带有几个节点的 JTree。当我启动该程序时,我只能看到节点图标(例如文件夹或文件),而看不到与它们关联的名称。我可以展开和折叠节点。当我调试时,我发现节点设置了正确的数据,无论我在构建模型时使用什么。在这个程序中,我为 JTree、TreeModel、DefaultMutableTreeNode 编写了包装器。可能是什么问题?任何指示都会有很大帮助。 ——保罗
I've written a JTree with couple of nodes. When I launch the program, I only see the node icons like folder or file and not the names associated with them. I could expand and collapse the nodes. When I debug, I see that the nodes are set with proper data whatever I used while building the model. In this program, i've written wrappers for JTree, TreeModel, DefaultMutableTreeNode. What could be the problem? Any pointers would be of great help.
-Paul
抱歉没有发布更多详细信息/代码。无论如何,我发现我的代码有问题。问题是我重写了类中的 toString() 方法,该方法用于设置树节点的用户对象,但返回 null。由于该方法返回 null,因此没有显示任何内容。我让它返回要显示的字符串。现在运作良好。
谢谢各位..!
Sorry for not posting more details/code. Anyway, I've found the problem with my code. The problem was that I had overridden the toString() method in the class that I use to set as user object for the tree node, but that was returning null. As the method was returning null, there was nothing displayed. I made it to return the string to be displayed. It is working good now.
Thanks guys..!