Speed up collapse and expand in JTree
JTree is slow… Google this and you will find it is a well known problem. For one of my application I need to do collapse and expand operations on all nodes of a large JTree. Even with the large model flag set it’s take 20 seconds to expand the whole tree. Profiling the execution with Netbeans profiler we can see that 100% of the time is took be the UI. It seems to propagate changes to the UI after the expand/collapse of each nodes. So a way to speed up this is to remove the UI during the operation:
TreeUI ui = myJTree.getUI(); myJTree.setUI(null); massExpand(myTreeRoot); myJTree.setUI(ui);
Categories: Uncategorized
Java