By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,470 Members | 1,907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,470 IT Pros & Developers. It's quick & easy.

TreeModel events problem

P: n/a
Hello,

I have a problem to catch tree events using a JTree associated with a
custom TreeModel. I would like an editable JTree, and when the user
updates some nodes of the tree, I would like the model also updated
and view the update. But in my case when the user updates a node, the
old value remains. What am I doing wrong?

Thanks

Here is my code:

public class XMLTreeModel implements TreeModel {

[... Other methods of TreeModel interface]

private Vector listenerList = new Vector();
public void addTreeModelListener(TreeModelListener listener) {
if(listener != null && !listenerList.contains(listener)) {
listenerList.addElement(listener);
}
}

public void removeTreeModelListener(TreeModelListener listener) {
if(listener != null) {
listenerList.removeElement(listener);
}
}
}

----

public class XMLTreeModelListener implements TreeModelListener {

public void treeNodesChanged(TreeModelEvent e) {
System.out.println("Wassup");
}

public void treeNodesInserted(TreeModelEvent e) {
System.out.println("Wassup1");
}

public void treeNodesRemoved(TreeModelEvent e) {
System.out.println("Wassup2");
}

public void treeStructureChanged(TreeModelEvent e) {
System.out.println("Wassup3");
}
}

---

JTree t = new JTree();
t.setEditable(true);
xmlTreeScrollPane = new JScrollPane(t);
....
XMLTreeModel xmlTreeModel = new XMLTreeModel(doc); // doc is an XML
Document
xmlTreeModel.addTreeModelListener(new XMLTreeModelListener());
t.setModel(xmlTreeModel);
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Sydney wrote:
Hello,

I have a problem to catch tree events using a JTree associated with a
custom TreeModel. I would like an editable JTree, and when the user
updates some nodes of the tree, I would like the model also updated
and view the update. But in my case when the user updates a node, the
old value remains. What am I doing wrong?


Does your custom TreeModel implement valueForPathChanged()?

HTH,
Ray

--
XML is the programmer's duct tape.
Jul 17 '05 #2

P: n/a
No, It's the only one I did not implement

Sydney

Raymond DeCampo <rd******@spam.twcny.spam.rr.spam.com.spam> wrote in message news:<tm******************@twister.nyroc.rr.com>.. .
Sydney wrote:
Hello,

I have a problem to catch tree events using a JTree associated with a
custom TreeModel. I would like an editable JTree, and when the user
updates some nodes of the tree, I would like the model also updated
and view the update. But in my case when the user updates a node, the
old value remains. What am I doing wrong?


Does your custom TreeModel implement valueForPathChanged()?

HTH,
Ray

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.