Is there a fast way to expand many paths in a JTree?

杀马特。学长 韩版系。学妹 提交于 2019-12-11 04:35:29

问题


I have a large JTree and I need to expand thousands of nodes all at once. Right now, that is taking a long time. I think it's because it's firing notifications and doing all the work for every one. Is there some way to tell it to expand all the nodes in a batch so it only has to update things once afterwards?

Or some other way to make expanding lots of nodes in a batch faster?


回答1:


Have you tried disabling the tree's event listeners? That way it won't fire off events every time you modify the tree. Something like this:

setVisible(false);
tree.removeTreeWillExpandListener(this);
tree.removeTreeSelectionListener(this);

//modify the tree

tree.addTreeSelectionListener(this);
tree.addTreeWillExpandListener(this);
setVisible(true);


来源:https://stackoverflow.com/questions/4250569/is-there-a-fast-way-to-expand-many-paths-in-a-jtree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!