• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TreeModel

 
seema chhetri
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello,

Thanks for replying but i have to implement all the methods of TreeModel Interface. I don't have to do with DefaultMutableTree.
My code i have given before please tell me why the "+" or "-" sign are not coming.
So, please help me out.



Thnaks & Regards,
Seema
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Swing forum since I don't see the connection to Oracle.

Also read this for why saying your question is "urgent" doesn't help matters.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you create an empty JTree
new JTree();
you'll get a default treeModel showing colors, sports, food

this is from the sorce code of JTree (which is what YOU should have done in your urgent research)

 
seema chhetri
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,


Thanks for repplying , but i dont have to use a DefaultMutableTreeNode.as i want any simple Jtree with TreeModel.
Please give me any simple Jtree using TreeModel.






Thanks & Regards,
Seema
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Recommended reading
http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html

Please show some effort before posting, as you end up wasting everybody's time.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Please give me any simple Jtree using TreeModel.

you have it now.

again, this is what YOU should be doing

from JTree's source, the default constructor (new JTree())


which calls this constructor

and supplies it, from the return value of getDefaultTreeModel(), .....wait for it..... a TreeModel

had you taken the time to read the code posted earlier you would seen that you already had your treemodel.
please move your feet away from the screen so you can see it all.
 
Rob Spoor
Sheriff
Pie
Posts: 20493
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seema chhetri wrote:My code i have given before

And where would that be? Next time, please provide a link to it.

For future reference, this thread contains the code.

please tell me why the "+" or "-" sign are not coming.

Probably because your implementation of getChildCount() and isLeaf() is not correct. This method looks especially dodgy:

Also, this seems completely wrong:
If there are no children, it's not a leaf? If it has children, it's a leaf? Shouldn't that be the other way around?
 
seema chhetri
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,


Thanks For Repplying,


please can anyone send me simple code of jtree using Treemodel.



Thanks & Regards,
Seema
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> please can anyone send me simple code of jtree using Treemodel.

boring....


JTree tree = new JTree();
 
Rob Spoor
Sheriff
Pie
Posts: 20493
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seema chhetri wrote:please can anyone send me simple code of jtree using Treemodel.


Maneesh Godbole wrote:Recommended reading
http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html

Please show some effort before posting, as you end up wasting everybody's time.
 
seema chhetri
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Thanks for reppliying.i have used a tree model but i m not able to add a node in the frame .so please suggest me how i can add a node in the frame i tried many way but fail.
i m sending you one file it has a supporting four files also but i m sending only one main file please help me in getting node in the frame.

thanks And Regards,
seema
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where are you adding the node, what's the problem?

if you're getting a NPE, the problem line is here
JTree tree = new JTree(treeModel);
and you'll need to think about why that line is a problem.
 
seema chhetri
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,


yes, its giving an Null Pointer Exception .
can i know what i have to pass a value in an vector in TreeModel. so that it ll work.


thanks
seema
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> can i know what i have to pass a value in an vector in TreeModel. so that it ll work.

that has nothing to do with your NPE.

JTree tree = new JTree(treeModel);
is local to createTreePanel()
you almost had it right with the line (commented out) that follows the above line
// tree = new JTree(jTreeRootNode);

put the two together and you get
tree = new JTree(treeModel);
 
seema chhetri
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
now it is working but it data is coming with object. And it is not fetching a data .




Thanks
seema
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> And it is not fetching a data please see my code and tell me what to do.

how do you know it's not fetching data?

if it is this line
System.out.println("obj.getRoot()###"+obj.getRoot());
then that's not the treeModel with the data.

if it is something else, you'll have to start debugging
1) get rid of all non-problem parts - colors, fonts, images etc
2) add some println()'s to see if suspected values are correct.
3) use hard-coded data, see if it displays OK, if so, problem could be where you're getting data from
etc
 
seema chhetri
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

i m sending you my tree model code there is an problem in getchildcount (); i m basically want a plus sign in the jtree
its coming but when i click any of the module its showing class cast exception.

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>there is an problem in getchildcount (); i m basically want a plus sign in the jtree

what does a 'plus sign' have to do with getChildCount()?

if you look at your getChildCount(), it only contains 2 lines other than the 'return' line,
and both of those you don't do anything with the local variables created, so get rid of them.


> give mail id if possible so that i can send you all the file .

http://faq.javaranch.com/java/UseTheForumNotEmail
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic