Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree Scalablity ???

 
myron schabe
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I code a JTree to just create nodes for what is in the viewable area? (i.e. if JTree is in a scrollPane, which is say 600 high to only create and show the leafs/nodes that would show up in the 600 pixel high scrollpane).
Also, any advice regarding scalablity/performance solutions/patterns with a JTree would be very helpful.
Many Thanks
 
Philip Borlin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A couple of suggestions.
It is really important that you pay attention to how you fire events in your TreeModel that will be picked up by your TreeModelListeners. Only fire events for those nodes that changed.
Your JTree will figure out which nodes need to be displayed on the screen and call getChild(Object parent, int index) on your TreeModel. If you write your own implementation of TreeModel you can control how your tree nodes are accessed. When you create your tree nodes put two methods in it - one to return how many children there are, and a second to retrieve a particular node. This way you don't even have to load a particular child until it is needed.
As to performance patterns - lazy initialization of nodes and well targeted events are going to be two sure bets.
Originally posted by myron schabe:
How can I code a JTree to just create nodes for what is in the viewable area? (i.e. if JTree is in a scrollPane, which is say 600 high to only create and show the leafs/nodes that would show up in the 600 pixel high scrollpane).
Also, any advice regarding scalablity/performance solutions/patterns with a JTree would be very helpful.
Many Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic