My method getChild(Node parent, int index) return either the initial Books List (for the root node), either a "Book" object, either a Set for the node "Characters", "Chapters", "Pictures", and "Character" "Picture" an "Chapter" when exploring the Sets.
My problem is that it appears that the two empty sets are supposed to be "equals" for the java language.
So When I return several empty sets (a newly created Book doesn't contains any chapters not pictures yet, so the sets are empty ! ), the tree considers them as the SAME NODE, so my Tree contains holes in it ! Only the last returned empty Set is displayed (logic).
Since I didn't found any 'elegant' way to dodge that probleme (doesn't want to subclass Set to override equals or such a ugly thing), I'm returning to the community to point me towards an elegant one !
Here's a suggestion that uses off–the–shelf classes to put this together. In the JTree in the app below each TreeNode is a DefaultMutableTreeNode. The getUserObject method of the DefaultMutableTreeNode calls the toString method of the object given to the DefaultMutableTreeNode as userObject. To allow the Book class to avoid its toString method being called by getUserObject, the Book is wrapped in a BookWrapper whose toString method returns the Book title to the inquiring getUserObject method. This leaves the Book class toString method free to return its relevant data.