Does anyone have idea on how to make some specific nodes in JTree as non editable.
My tree structure is as follows:
Root 1
|
Parent 1
|
Child 1
......
Child n
.....
|
Parent n
Root 2
Root 3
......
Root n
where I want the nodes Root 1, Root2....Root n to be non editable.
But the Parent nodes and child nodes to be editable.
The tree has popup which has options for renaming these nodes.
So I have set as follows
tree.setEditable(true);
How to make nodes Root 1, Root2....Root n to be non editable?
Use a custom TreeCellEditor and implement its isCellEditable method:
Alternatively, you can return a different editor component:
This will return a JLabel for editing the root and its direct children instead of a JTextField.
When I click on the Parent and child nodes I am able to edit the node with MyTextField. I want Parent nodes to be of legth 15 where as the child nodes to be of length 20. How can I achieve this?
With the following code, I am getting both Parent and Child nodes to be of size 20. But I want different sizes. Please help me out!!!
I have done as follows. But I am getting ClassCastException in the return statement.Even I tried with JTextField also. I am getting the same exception
In the NonRootEditor class I have written as follows:
Suganthi Velliah wrote:Please tell me where the flaw is?
Apparently, DefaultTreeCellRenderer does not directly return the text field but wraps it in a Container subclass. DefaultCellEditor does not have this problem, so you should be able to use that one instead.