This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
Similar Threads
JTree Leaf Node Folder
Icon change while editing tree node
nodes with no children are displayed as a leaf nodes in JTree
JTree node as non editable
Branch nodes editable