Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTree binding to JTextField, ask user to save data  RSS feed

 
Viktor Grafskiy
Greenhorn
Posts: 7
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!