JTree - Save and load from an array?
I'm trying to allow users to create a hierarchy of folders from a Java gui page.
I found the best representational method of showing a hierarchy of folders to a user with a gui is with a JTree?
I can create a JTree, but i need the user to be able to add/remove and modify nodes on the JTree to reflect the folder structure they want to create.
This JTree then needs to be saved (in a database) so that on another day, this folder structure can be edited by the user. So I need to populate a JTree from the database values already saved and display the editable JTree to the user for further editing.
Then on another day, the user will actually want to create the folder structure based on the JTree/database values. - I can do this directly from the database without having to display the JTree again.
I assume I can create an array from the JTree and store the values of the array in the database, then use those values in the database later to populate the array(s) and then build the JTree again from it. - Then to make the folder structure, just use the values from the database?
I have spent a whole day on this, and I came across this example:
Using Swing Components: Examples (The Java™ Tutorials > Creating a GUI with JFC/Swing > Using Swing Components)
from here: How to Use Trees (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components) (See: Dynamically Changing a Tree)
^ This is great because it allows the user to edit the tree.
Basically, I can write methods to write something to the database, retrieve it back and actually create the folders, but I am having no hope at all in dynamically saving or loading a JTree from say an array(from the database).
I have no preference on if i use arrays or other data structure, as long as its not too difficult to loop them and put the values in the database.
If anyone can help, that really would be amazing.
(Attached a picture to help explain)