wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes DefaultTreeModel & JTree 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 "DefaultTreeModel & JTree" Watch "DefaultTreeModel & JTree" New topic
Author

DefaultTreeModel & JTree

Lars Dold
Greenhorn

Joined: Apr 09, 2010
Posts: 9
Hello,

I have a curios problem with a JTree.
When I use my own extended class for the TreeModel the Tree would not be filled, if I use the DefaultTreeModel directly it works.
What do I make wrong with my own TreeModel?

My TreeModel:

Call in the UI Class:
This don' t work:


This work:


I thought that when I extend my class with the DefaultTreeModel I will Inheritance all the function of superClass. Did I miss something?

Thank you very much

kind regards

Lars
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Is it just me or you're not using TreeViewModelNew at all ? Just a typo ?


[My Blog]
All roads lead to JavaRanch
Lars Dold
Greenhorn

Joined: Apr 09, 2010
Posts: 9
Hello,

ups this was a copy and past failure, in eclipse my class is correct, I edit the posting above.
There is no failure message, just a empty JTree, when I use childcount in my TreeViewModel, it shows me an count of 1, but nothing in the JTree,

kind regards

Lars
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Shouldn't you add the new node to the root of the tree ?
Lars Dold
Greenhorn

Joined: Apr 09, 2010
Posts: 9
Hello Christophe,

thank you very much for your fast help, this was the Point:

ptNode = new DefaultMutableTreeNode(root);

The failure was not to use the original root variable, the new created variable ptNode is different to the original root variable,

kind regards

Lars
 
Consider Paul's rocket mass heater.
 
subject: DefaultTreeModel & JTree
 
Similar Threads
custom icons in JTree
JTree
JTree Expansion
JTree
JTree errors with treeModel.nodeChanged()