aspose file tools
The moose likes Swing / AWT / SWT and the fly likes JTree binding to JTextField, ask user to save data Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "JTree binding to JTextField, ask user to save data" Watch "JTree binding to JTextField, ask user to save data" New topic
Author

JTree binding to JTextField, ask user to save data

Viktor Grafskiy
Greenhorn

Joined: Jul 26, 2012
Posts: 4
Hi all.
I have a Swing application which connects to database with using of JPA(EclipseLink). There is a special form in the application, which contains JTree and some JTextFields. JTree is filled by enitities from database. When user clicks on a leaf of JTree, chosen entity is binding its fields to JTextFields. The problem is I don't know how i can determine if user made any changes in textfields or not. When user is choosing another leaf in the JTree I would like to ask him whether he wants to save changes or not, but he should be asked only if changes were really made. Please give me an advise how could I implement such a scheme? I was thinking to do it with help of JPA, but JPA EntityManager doesn't have any methods which could show me that Entity is "dirty". Thanks in advance.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if there's only a few textfields, perhaps a DocumentListener might suit.

depending on how you've structured your code, you may need to remove the listener
prior to selecting a new leaf (which populates the textfields with respective data),
then adding it back, after leaf selection.
Viktor Grafskiy
Greenhorn

Joined: Jul 26, 2012
Posts: 4
Michael Dunn wrote:if there's only a few textfields, perhaps a DocumentlListener might suit.

Michael, thank you my friend, that DocumentlListener really helped me.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: JTree binding to JTextField, ask user to save data
 
Similar Threads
JTree: How to update nodes?
JTree
JTree reload question, AGAIN
Lazy fetching JTree
Updating a JTree