• 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
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Jtree with its Modules

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ,

I have made one Jtree in which its have 26 modules around when i click on any of them again all 26 modules is coming from that node please see my code and let me know what to do.


Thanks
seema
 
Sheriff
Posts: 22248
117
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I couldn't compile your code because of several missing classes, but your TreeModel code looks really bogus. There are always 2 children (getChildCount), but if the JTree tries to get these it always gets a completely new object. If it then try to get the index of an object, 0 is always returned. And nothing is a leaf, ever.

The following are usual implementations:
- each object has an associated List (or array); let's call it children
- getChildCount(o) returns children.size() (children.length for the array)
- isLeaf(o) returns children.isEmpty() (children.length == 0 for the array)
- getIndexOfChild(o, child) returns children.indexOf(child) (a loop to retrieve the index for the array)
- getChild(o, index) returns children.get(index) (children[index] for the array)

Usually this List (or array) is stored as part of the object (e.g. DefaultMutableTreeNode) or can be constructed using the object.

For instance, a naive (very slow) File tree model (missing a few methods):
 
seema chhetri
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,


thanks for repplying .but the main problem is that i dont want any leaf. I only want root then after this modules no child of these modules.

please tell me what can be possible for this code.


Thanks
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic