Home > Uncategorized > Speed up collapse and expand in JTree

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 Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.