我有jTree(例如):
-paper
-coated
-glossy
-hummermill
-quatro
-springhill
-matte
Run Code Online (Sandbox Code Playgroud)
当我选择springhill我得到5的索引,但我不想从根(纸)(包括父母和光泽外的其他节点)计数,我想从hummermill开始计数所以我试图获得2的索引.
我使用tree.getLeadSelectionRow()并获得5的int值; 我也使用node.getIndex(node)但在这里我没有得到任何正常的(0,3,-1).我尝试了节点和树的所有方法的所有变化,并找不到任何有用的东西.请求帮助!
您必须从其父节点中找到节点的索引
DefaultMutableTreeNode node=(DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
System.out.println(node.getParent().getIndex(node));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1475 次 |
| 最近记录: |