aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes 2 Questions on SWING events Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "2 Questions on SWING events" Watch "2 Questions on SWING events" New topic
Author

2 Questions on SWING events

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 590
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

Joined: Jun 19, 2010
Posts: 825
    
    5

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.


The quieter you are, the more you are able to hear.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: 2 Questions on SWING events