File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Enable/Disable editing of Tree Node Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Enable/Disable editing of Tree Node" Watch "Enable/Disable editing of Tree Node" New topic

Enable/Disable editing of Tree Node

kapil Gupta
Ranch Hand

Joined: Dec 17, 2001
Posts: 89
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
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

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 ).

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: Enable/Disable editing of Tree Node
It's not a secret anymore!