• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Improving performance of JTree ?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

I have written a TreeNode which holds all local & removable discs, and creates an entire tree of the directories (not the files!) underneath it (working on windows xp).
I get the desired results (eg. the right directories etc), but performance really seems to be an issue. It's not that it won't work well, but I do believe it should be faster for a nice user experience

I listed the code here, I am hoping some of you experienced Java coders could give me some pointers and tips to improve performance? When I click on a node, it takes a while before it opens up sometimes, especially if there are a lot of subdirectories. The JTree is put inside a JScrollPane, and scrolling doesn't go as fast as it should be sometimes. And could setOpaque( false ) also be a huge problem? It's ok that the first time a directory is opened, it takes a little while, but it should work faster as soon as the Children have been loaded into memory, no?





I am becoming a bit worried because the computers at school on which I have to showcase this application aren't even as fast as my own system here at home, whoops :-)

Thank you in advance for any pointers and tips :-)

Regards,
Steven
 
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about not adding childs to a node before expanding?

Let's say we have a root node that is c:\

you need to implement the hasChild, childCount. When clicking the root you load the next step into the tree. This can be done with all the nodes.
If you use java.io.File as an object in DefaultMutableTree node you should get this to work.
 
Sheriff
Posts: 22647
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should also consider caching the results of File.list calls. I've created my own FileTreeModel (not TreeNode but similar), and ran into the same problem. The cause was the number of calls to File.list:
- in getChildCount()
- in getChildAt() for all children
- in isLeaf() for all children

As the number of visible nodes increases, the number of calls to File.list increases even harder. By caching the results and using that cached value, your tree will be a lot faster already. That does cause your tree to be out-dated at times, but by refreshing the cache (e.g. on each call to getChildCount()) you can solve that.
 
Steven Rombauts
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you both for the useful tips!

Caching the results of the file.list() method did improve the performance of my tree quite a bit! It runs great now :-)
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...
[MG]Removed hijack
 
Kriss Reddy
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...
[MG]Removed hijack
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kriss,
Please do not hijack other people's threads.
You can start a new thread to post your question
http://faq.javaranch.com/java/UseOneThreadPerQuestion
 
Kriss Reddy
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Sorry for hijacking, My intention was to take advantage of the problem described here. I will not hijack again.

Thanks.
 
What is that? Is that a mongol hoarde? Can we fend them off with this tiny ad?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic