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.
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
posted
0
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
posted
0
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.
> 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.
Please show some effort before posting, as you end up wasting everybody's time.
seema chhetri
Ranch Hand
Joined: Feb 17, 2009
Posts: 41
posted
0
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
posted
0
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
posted
0
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
posted
0
> 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
posted
0
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
posted
0
> 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
posted
0
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
posted
0
>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 .