给分问题:如何展开JTree中的节点,内在细说……在线,解决即给分…… expandPath()方法可以展开节点。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 expandPath public void expandPath(TreePath path) Ensures that the node identified by the specified path is expanded and viewable. Parameters:path - the TreePath identifying a nodejTree1.expandPath(yourNode.getPath()); namowen(寒号不已):小小不然:)jTree1.expandPath(new TreeNode(yourNode.getPath()));qqf(我就是我) :〉〉树形控件一马上显示新增的节点,而是点击其它节点时才有。 什么意思? 错了namowen(寒号不已):小小不然:)jTree1.expandPath(new TreePath(yourNode.getPath()));qqf(我就是我) :〉〉树形控件一马上显示新增的节点,而是点击其它节点时才有。 什么意思? 这个问题没这么简单:JTree只是用来显示的,数据结构却是放在TreeModel里的(一般都是DefaultTreeModel)。如果你用insertNodeInto()这个method,那么DefaultTreeModel被更新后,将自动更新JTree的显示,但它不会自动扩展新添node的parent,这也就是你的问题。这里有一个解决办法:1、要显示每个新添node,就要扩展从root到它的parent的每一个node。要有一个方法能够找到从当前新添的node到root这条tree path上的每一个parent;2、可以用getPathToRoot()这个method,它返回一个TreeNode数组,保存了从新添node到root的所有node;3、然后用makeVisible()将新添的node显示出来。源代码:TreeNode[] nodes = model.getPathToRoot(newNode);TreePath path = new TreePath(nodes);tree.makeVisible(path);model就是object of DefaultTreeModel,tree就是object of JTree。另外,如果你的tree用了滚动条,有必要用下面的语句替换掉上面最后一句代码:tree.scrollPathToVisible(path);这样就扩展path上的所有node,并且让滚动条移到新添node的位置。 这个问题我遇到过,解决方法如下:DefaultTreeModel model = (DefaultTreeModel)jTree_project.getModel();model.setRoot(root);model.nodeStructureChanged(first_root); 酷,成了,谢谢各位的帮助, farawayzheng_necas(遥远) 说得不错,namowen(寒号不已)的有点一点小问题照上改就可以了。谢谢两位,谢谢大家! java做一个计算器 一个关于java中String类方法的问题 java多线程问题 web-inf的class下怎么没有文件呀 急!在线等!file问题 bao110908 请教问题 请问个socket简单问题 求助!java有没有对powerpoint进行操作的API? 请教一下关于异常处理的问题 jbuilder 在使用中,经常出现提示为:java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]连接占线导致另一个 hstmt,是什么意思,怎样解 难道没有人可以告我如何在applet中使用jni方法吗?
public void expandPath(TreePath path)
Ensures that the node identified by the specified path is expanded and viewable.
Parameters:path - the TreePath identifying a nodejTree1.expandPath(yourNode.getPath());
小小不然:)
jTree1.expandPath(new TreeNode(yourNode.getPath()));
qqf(我就是我) :
〉〉树形控件一马上显示新增的节点,而是点击其它节点时才有。
什么意思?
namowen(寒号不已):
小小不然:)
jTree1.expandPath(new TreePath(yourNode.getPath()));
qqf(我就是我) :
〉〉树形控件一马上显示新增的节点,而是点击其它节点时才有。
什么意思?
JTree只是用来显示的,数据结构却是放在TreeModel里的(一般都是DefaultTreeModel)。如果你用insertNodeInto()这个method,那么DefaultTreeModel被更新后,将自动更新JTree的显示,但它不会自动扩展新添node的parent,这也就是你的问题。这里有一个解决办法:
1、要显示每个新添node,就要扩展从root到它的parent的每一个node。要有一个方法能够找到从当前新添的node到root这条tree path上的每一个parent;
2、可以用getPathToRoot()这个method,它返回一个TreeNode数组,保存了从新添node到root的所有node;
3、然后用makeVisible()将新添的node显示出来。源代码:
TreeNode[] nodes = model.getPathToRoot(newNode);
TreePath path = new TreePath(nodes);
tree.makeVisible(path);
model就是object of DefaultTreeModel,tree就是object of JTree。另外,如果你的tree用了滚动条,有必要用下面的语句替换掉上面最后一句代码:
tree.scrollPathToVisible(path);
这样就扩展path上的所有node,并且让滚动条移到新添node的位置。
DefaultTreeModel model = (DefaultTreeModel)jTree_project.getModel();
model.setRoot(root);
model.nodeStructureChanged(first_root);