Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Enable/Disable editing of Tree Node  RSS feed

 
kapil Gupta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a JTree with parent nodes and leaf nodes. I want to make the parent nodes editable and leaf nodes non-editable. How can I prevent editing of leaf nodes by user
Thanks,
Kapil
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make your tree editable, but use a custom TreeCellEditor to prevent leaf cells from being edited. I think pretty much all you'd have to do is extend DefaultTreeCellEditor, and in the getTreeCellEditorComponent() method just call setEditable( !leaf ).
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!