Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

2 Questions on SWING events

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) How do I know any fields on the JFrame window is changed or touched? Currently I used a static variable, but don't know when to change it to "true",
I have tried to set the flag in JFrame.propertyChanged. But it is true always whenever I quit the form.
2) If I am editing a cell on a JTable whilst I quit the form, the data is not saved. How do I prevent that from happening? How do you find out the values on the JTable Cell that is left out orphan?
Thanks
Jack
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) How do I know any fields on the JFrame window is changed or touched?

Depends on what you mean by "changed or touched" and what fields are in question.
If by "touched" you mean "focus", then you might want to take a look at How to Write a Focus Listener tutorial. As for "changed" I can only assume you are talking about text components, though I would recommend How to Write a Document Listener tutorial. For any other case (if I was wrong) you would need to be more specific.

2) If I am editing a cell on a JTable whilst I quit the form, the data is not saved. How do I prevent that from happening? How do you find out the values on the JTable Cell that is left out orphan?

You'll probably need to TellTheDetails about this case too. In general I would point you to Listening for Data Changes tutorial. You might find this blog post interesting for the purpose, too.

But until you provide some more details about your problem, that's all I can tell you. A lot of material to read, but certainly useful.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 2) If I am editing a cell on a JTable whilst I quit the form, the data is not saved. How do I prevent that from happening?

set the default close operation to DO_NOTHING_ON_CLOSE
add a windowListener, and in windowClosing you check the status
of a dirtyData flag to see whather to exit, or to save, or to give user option to save.

a listener to your tabel would set the flag to dirty on any change, and when saved,
flag set to OK
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic