This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTree Scalablity ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree Scalablity ???" Watch "JTree Scalablity ???" New topic
Author

JTree Scalablity ???

myron schabe
Greenhorn

Joined: Aug 21, 2002
Posts: 19
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

Joined: Sep 11, 2002
Posts: 3
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
 
jQuery in Action, 2nd edition
 
subject: JTree Scalablity ???