This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

treeNodesChanged event

 
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
 
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
 
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!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!