aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Updating edited tree to database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Updating edited tree to database" Watch "Updating edited tree to database" New topic
Author

Updating edited tree to database

kiran cy
Greenhorn

Joined: Aug 24, 2012
Posts: 24

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

Joined: Jun 19, 2010
Posts: 825
    
    5

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.


The quieter you are, the more you are able to hear.
kiran cy
Greenhorn

Joined: Aug 24, 2012
Posts: 24
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
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

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

Joined: Aug 24, 2012
Posts: 24
How to recognise the drag n drop event using treemodel listener..
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1085
    
  10

Drag & Drop is differently handled and is not related to TreeModelListener. I suggest you go through the tutorial to first understand drag & drop.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Updating edited tree to database