SWT TreeViewer is slow when filling with many elements

时间秒杀一切 提交于 2020-01-24 14:13:46

问题


I'm new in the java world, so I'm sorry if my question is trivial.

I'm developing a Eclipse view part, and I'm filling a SWT tree view with the following data structure. All data is in memory:

Node1
   Child1
   Child2
Node2
   Child1
   ...
   Child2915

I think that is not a very big tree, but it is slow being drawn (10 seconds). I have manage trees in .NET with more than 10.000 elements and it loaded smoothly. I don't know if I've implemented the code, but the same problem appeared in .NET if I did not call BeginUpdate() - EndUpdate().

Must I call something similar in Java/SWT? Any other tips about why the tree is so slow?


回答1:


You could use the SWT.VIRTUAL flag when creating the Tree to help with the performance

For more information, see this article on Virtual Trees and Tables

This can also be combined with the JFace TreeViewer. See this article on the JFace TreeViewer for more details (although this doesn't specifically mention the virtual flag)




回答2:


Finally, I used setRedraw(boolean value) after calling refresh in my TreeViewer.

public void refresh() {
    try {
        mTreeViewer.getControl().setRedraw(false);
        mTreeViewer.refresh(true);
        mTreeViewer.expandAll();
    }
    finally {
        mTreeViewer.getControl().setRedraw(true);
    }
}


来源:https://stackoverflow.com/questions/7595495/swt-treeviewer-is-slow-when-filling-with-many-elements

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