This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes TreeModel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "TreeModel" Watch "TreeModel" New topic
Author

TreeModel

seema chhetri
Ranch Hand

Joined: Feb 17, 2009
Posts: 41

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

See the Swing description of what to implement


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Feb 17, 2009
Posts: 41
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

Joined: Jul 26, 2007
Posts: 10167
    
    8

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Oct 27, 2005
Posts: 19649
    
  18

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?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
seema chhetri
Ranch Hand

Joined: Feb 17, 2009
Posts: 41
Hello ,


Thanks For Repplying,


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



Thanks & Regards,
Seema
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> please can anyone send me simple code of jtree using Treemodel.

boring....


JTree tree = new JTree();
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

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

Joined: Feb 17, 2009
Posts: 41
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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Feb 17, 2009
Posts: 41
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

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Feb 17, 2009
Posts: 41
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

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Feb 17, 2009
Posts: 41
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

Joined: Jun 09, 2003
Posts: 4632
>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
 
Consider Paul's rocket mass heater.
 
subject: TreeModel
 
Similar Threads
JTee
TreeModel for the FileSystem c:/ d:/
Why Interfaces Came into Picture ?
How to get JTree object of parent node of DefaultMutableTreeNode object?
Sorting JTree Nodes alphabetically