【发布时间】:2013-07-20 18:49:10
【问题描述】:
对于从数组中读取数据并将其添加到 JTree 的 for 循环的语法有困难。
public void init()
{ final String section1 = "JAVA";
String[] sections = new String[]{ "Tutorial6", "Tutorial5", "Tutorial4", "Tutorial3", "Tutorial2", "Tutorial1" };
String contents[][] = {
{"content1a", "content1b"},
{"content2a", "content2b"},
{"content3a", "content3b"}
};
title = new DefaultMutableTreeNode(section1);
for (int i=0; i<sections.length; i++)
{ selection = new DefaultMutableTreeNode(( sections[i]));
selection.insert(new DefaultMutableTreeNode((contents[i])),0);
//title.insert(selection,0);
}
添加部分工作正常,但向这些部分添加节点是个问题。如何让 for 循环工作,以便在解析 for 循环时将具有内容名称的节点添加到相关部分??
这是不工作的代码:
selection.insert(new DefaultMutableTreeNode((contents[i])),0);
谢谢!!
【问题讨论】:
-
请说明这与您之前关于同一主题的问题有何不同:JTree - how to add nodes with a For-Loop?