Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree SubTree

 
Pamela Ng
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic