This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have jtree in a frame which can be editable. I have written the data present in it into database. Now, i made some changes in the jtree and i want to make them updated automatically to database when i edit tree.
How to do it ? Please suggest the basic structure of the program
Add a TreeModelListener to your tree model. The listener should watch for the treeNodesChanged method to be called.
That method will only tell you when nodes of the tree are changed. You will then have to write some code which gets the new values of those nodes, based on the TreeModelEvent which you got in the listener method.
That takes care of identifying when nodes change and what their changed values are. As for updating the database... there's not much to be said by somebody who knows nothing about your database and what the nodes of your tree mean. If you don't know anything about updating databases, I recommend reading the JDBC tutorial. (Google keywords: jdbc tutorial.)
Joined: Aug 24, 2012
How to recognise the drag n drop event using treemodel listener..
kiran cy wrote:Here he is doing nothing related to database. how to read the edited contents from the jtree in jframe and update them to database
I said it's similar to what you need; actually, if you pay attention to this example, it contains almost everything you need for your solution (unfortunately for you, it's not working with database, but it's something you could add very quickly.
kiran cy wrote:How to recognise the drag n drop event using treemodel listener..
I suppose that question should be posted in another thread, since it has nothing to do with your original question in this one.