This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JTree problem

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I've got an app where I'm trying to dynamically insert nodes into a JTree
So, I have a button whose event handler looks like this


try
{


TreePath parentPath = m_app.jTree1.getSelectionPath();
DefaultMutableTreeNode node = (DefaultMutableTreeNode)parentPath.getLastPathComponent();
DefaultMutableTreeNode child = new DefaultMutableTreeNode("foo");
m_app.treeModel.insertNodeInto(child, node, 0);
//m_app.treeModel.reload();
m_app.jTree1.scrollPathToVisible(new TreePath(child.getPath()));
}
catch(Exception e)
{
System.out.println("Error in jButton1ActionPerformed = " + e.toString());
}
}



where "m_app.jTree1" is the tree
when I click the button a node get's properly inserted into the selected node as long as that node has no children.
If it has children, nothing happens
no node
no exception
no nothing
I suspect there's something wrong with the way I'm getting the path to the currently selected node.

note: when the app starts, it build the initial tree from info in a database and everything works fine. it's just when I later try to dynamically add more nodes that I have a problem

Ideas??
Dave
 
Dave Robbins
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
figured it out
had to do with using the root node in the tree constructor rather than the treemodel

Dave
    Bookmark Topic Watch Topic
  • New Topic