How to speed up JTree TreeCellRenderer ?

I made a custom cell renderer which extends DefaultTreeCellRenderer,building leaf icons,while

comparing if they exist in another directory of files.

Now it is going through directory file list and compares each file name and time stamp against each file in

some other directory and sets an appropriate

leaf icon(equal,less or greater).So it is like double rendering.

It works fine with small number of files,for example on the desktop.

But when I try to use it on Windows NT network it took 2.5 min to load and then was frozen trying to respond

to a mouse click event.

What if you have 20 directories 250 files per each - it is a killer...

I tried to render only on expand, but the control goes to MyTreeCellRenderer before it response to mouse click,

that's why you have to click twice on the same

directory to display the correct icons.

TreeCellRenderer repaints cells constantly, which means looping through all nodes when you minimize,maximize

a window - and it is awfully slow... How to turn it off ?

Is there any way to speed up the process or swich the renderer off and on only when you need to ?

May be create another class holding all rendered JTees as a Vector or HashTable and get the right JTree

depending on the node you clicked?

Any help would be appriciated, cause I am stuck here..

Thanks,

Alex

[1460 byte] By [alex_step] at [2007-9-26 2:29:51]
# 1

Im not sure about ur code-describtion. But some weeks ago I made a Jtree displaying the filesystem, and I noticed it took some time walking through directories and files (if I created the whole tree at once). Instead I made the explore-mechanism only explore (and add nodes to a tree) 2 levels down in filesystem hierachy, (I needed to know if a node where a leaf or not) compared to ur selection in jtree. Maybe some similar approach could help u, im not quit sure from ur describtion, if u allready tried this. I dont think u can speed it up in any other way (unless ur code is bad!?), it takes some time reading all files/dirs in a filesystem.

Stig.

slackman at 2007-6-29 9:47:43 > top of Java-index,Archived Forums,Swing...
# 2
Thanks for reply!I tried to use the java defalt renderer not mine, and stillit takes 3 sec to build and show new directory.The problem is the painting of each node constantlywhen you move your mouse, click on a singlr node,etc.
alex_step at 2007-6-29 9:47:43 > top of Java-index,Archived Forums,Swing...
# 3

If your cell renderer is doing disk access every time it is called (that's what your description appears to say) then it is not surprising that you have performance problems when many nodes are displayed. Try to redesign your renderer to avoid that; for example, store the relevant information in the object you are putting into the tree node instead of recalculating it in the renderer. When I display a tree with a custom cell renderer I don't have that kind of problem even though my largest branch contains nearly 1000 nodes.

DrClap at 2007-6-29 9:47:43 > top of Java-index,Archived Forums,Swing...