我在这里发布的类中调用了addNotify()方法。问题是,当我在代码中调用addNotify()时,setKeys(objs)什么也不做。运行应用程序的浏览器中没有显示任何内容for cycle not works allright
但是,当我调用addNotify()没有循环(对于int ....),并且只添加一个项目到ArrayList,它显示正确的一个项目。
有谁知道哪里会出问题?见割让
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);
}
}
重新标记:这个问答真的没有任何“的NetBeans岬”给它。 – vkraemer 2010-03-22 16:24:32
原来这是为什么addNotify不起作用的问题。我在揭示问题的本质之后编辑了标题 – joseph 2010-03-22 16:30:50