I would like to create an index (1, 1.2, 1.3, 2.1 etc.) for each node of a JTree at the time of adding the new node,
i.e.
root
|
---1 node
|
---2 node
|
---2.1 node
Does anybody have an idea how I can do it? Thank you in advance for any answers.
Since you didn’t tell us, if you have implemented your own TableModel, I assume, that you work with a standard JTree and the default model. A method that retrieves the index of a Node as a String would look like this:
This code should work as long as you don’t build cycles into your tree, as if works recursively up to the root.