Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

JTree SubTree

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
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
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic