Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Updating edited tree to database

 
kiran cy
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is already similar topic here that you might use as a reference for what you need:
how to keep change after i edit the Jtree's leaves??

Craig Wood provided a good example you might want to go through.
 
kiran cy
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here he is doing nothing related to database. how to read the edited contents from the jtree in jframe and update them to database
 
Paul Clapham
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
kiran cy
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to recognise the drag n drop event using treemodel listener..
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Drag & Drop is differently handled and is not related to TreeModelListener. I suggest you go through the tutorial to first understand drag & drop.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic