SWT TreeViewer is slow when filling with many elem

2019-07-15 07:44发布

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?

2条回答
SAY GOODBYE
2楼-- · 2019-07-15 08:05

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);
    }
}
查看更多
Viruses.
3楼-- · 2019-07-15 08:08

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)

查看更多
登录 后发表回答