This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTree SubTree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree SubTree" Watch "JTree SubTree" New topic
Author

JTree SubTree

Pamela Ng
Greenhorn

Joined: Dec 20, 2008
Posts: 3
Hi,

Is there a way to just show part of a tree, as in a subtree. I use a JTree to create for eg:

- Map
|___- mapID
|______M2
- simulationID
|______S01
- mapDesc
|______None
- mapLength
|______490
- mapWidth
|______800
- mapScale
|______Scale_25000
- JunctionList
|______- Junction
|______- junctionID
|______- R10
|______- junctionType
|______- ROAD_TYPE_JUNCTION
......
......
|______- jConnectedTo
|______- BS5
......

The JTree is read from an XML document. And it can change dynamically depending on the XML document read, the JTree will show accordingly. There are somemore subnodes for Junction element, but for example, i want to stop at junctionType node. How do i do that? I have read several examples from other forums and tried but to no avail.

Another question: After i display this subtree, i want to link and display the remaining subtree by clicking a button, again display a small section of the subtree, by a count of 10 nodes by a refresh of the JTree. IThe count of nodes i mean by counting the main nodes, those nodes with + or -, Is it possible to do so? How do i do it? The examples i read online only give me the solution for displaying the whole tree and not part of a tree.

Help very much appreciated.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9995
    
    7

Welcome to the Ranch Pamela, we are happy to have you here

I have read several examples from other forums and tried but to no avail.
What problem did you run into when you tried it?

As you probably know, the JTree is just the "view" and is not aware of the data at all. All the data is encapsulated inside the TreeModel.
If you carefully go through the API for the TreeModel, you will find lots of convenient methods like getChildCount() and getChild() etc. If you haven't done so already, please do take out time to read this.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTree SubTree
 
Similar Threads
storing a UserPreferences for JTree
Displaying Data in a JTree
XML and JTree
JTree
Searching a JTree