我在这里发布的类中调用了addNotify()方法.问题是,当我在代码中调用addNotify()时,setKeys(objs)什么都不做.我的浏览器运行应用程序时没有任何内容.
但是当我调用addNotify()而没有循环(对于int ....),并且只向ArrayList添加一个项目时,它会正确地显示一个项目.
有谁知道哪里有问题?见cede
class ProjectsNode extends Children.Keys{
private ArrayList objs = new ArrayList();
public ProjectsNode() {
}
@Override
protected Node[] createNodes(Object o) {
MainProject obj = (MainProject) o;
AbstractNode result = new AbstractNode (new DiagramsNode(), Lookups.singleton(obj));
result.setDisplayName (obj.getName());
return new Node[] { result };
}
@Override
protected void addNotify() {
//this loop causes nothing appears in my explorer.
//but when I replace this loop by single line "objs.add(new MainProject("project1000"));", it shows that one item in explorer
for (int i=0;i==10;i++){
objs.add(new MainProject("project1000"));
}
setKeys (objs);
}
Run Code Online (Sandbox Code Playgroud)
}
看看这个循环:
for (int i=0;i==10;i++)
Run Code Online (Sandbox Code Playgroud)
这将从i = 0开始,并在i == 10时继续前进.我想你的意思是:
for (int i = 0; i < 10; i++)
Run Code Online (Sandbox Code Playgroud)
(为了清晰起见,添加了额外的空格.)