• Post Reply Bookmark Topic Watch Topic
  • New Topic

treeNodesChanged event  RSS feed

 
alex earnshaw
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there
Is there any way to tell what has caused a treeNodesChanged to be called?
I have a JTree which I have added a TreeModelListener to. The treeNodesChanged is being called in 2 situations:
1) when a tree node is expanded/collapsed, and
2) when a node is edited
I only want to take action when the node is edited, so how can I tell - is there something in TreeModelEvent that would tell me?
Thanks
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alex ... could you post some code? I tried to re-create this, and the "TreeModelListener" wasn't affected [called] at all when the tree nodes were expanded and/or collapsed. That's the job of the "TreeExpansionListener" (or "TreeWillExpandListener").
The "TreeModelListener" should only care about changes to the TreeModel itself, not how it's displayed.
 
alex earnshaw
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now you've said that I think I know why it is happening...I am actually using a JTreeTable (example downloaded from the Sun Swing tutorial) so I presume that is what is causing the problem, i.e. the JTreeTable is a JTable with a JTree as a renderer for the first column so the entire table row is seen as the node therefore any edit to the row (including an expansion or collapse) is seen as a node change.
I still don't know how to get around it though!
The JTreeTable code can be got at JTreeTable article
 
Bruno Dery
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I havent read all the code, but what do you mean by editing? You mean editing in the table cells?
My guess is that you're not listening for the right kind of event. Listening to the TreeTableModel wont do it in your case because of course you'll get all the events that happen to the model, and that includes expand/collapse of the tree (because rows need to be added / removed from the table). Instead you probably need to add a CellEditorListener to your table somehow (the standard JTable has it, so you probably just have to add it where you can access the JTable's reference). This will listen for the right event, and using that you should be able to obtain which row / column is being edited, and apply the changes to your model.
 
alex earnshaw
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes editing the cells. Your suggestion certainly sounds like a possible solution, will definitely give it a try!
Thanks!
 
alex earnshaw
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got that working now using the CellEditorListener!
Thanks again!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!