• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enable/Disable editing of Tree Node

 
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 ).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic