我在这里发布的类中调用addNotify()方法。问题是,当我像在代码中一样调用addNotify()时,setKeys(objs)什么也不做。在我运行应用程序的资源管理器中没有显示任何内容。
但是,当我在没有循环的情况下调用addNotify()(for 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);
}}
发布于 2010-03-23 00:09:53
看看这个循环:
for (int i=0;i==10;i++)这将从i= 0开始,一直到I == 10。我想你的意思是:
for (int i = 0; i < 10; i++)(添加额外的空格只是为了清楚起见。)
发布于 2010-03-23 00:21:48
乔恩是对的..。您的循环很可能是不正确的。
这是你的for循环到while循环的翻译,只是为了进一步澄清他的观察……
你的循环现在意味着...(在while-loop-ness中)
int i = 0;
while (i==10) {
objs.add(new MainProject("project1000"));
i++;
}
setKeys (objs);addNotify不会被调用,因为add永远不会被调用...
https://stackoverflow.com/questions/2493776
复制相似问题