0

How to write an event handling for a form to check whether any of its control values have changed? Here is my example in the simplest explanation as possible. I have a form, have a lot of controls on it. I need to prompt a dialog if any of its child controls values got changed. I can do this by having an event handler for all of its controls and use a Boolean flag so that when navigating away from that form I can check the flag and show the prompt. I think there should be a better way where we can write the event handling for the parent control (in this case the Form) and then whenever a child control value gets changed, it will trigger event handler declared with the form.

So instead of writing multiple event handling methods for each form control, how do we write just one method and capture all form controls events via that?

Thank you everybody!

Edit 1: Java Swing, Standard Java

Sanone
  • 11
  • 2
  • Java Swing, standard Java. Thanks – Sanone Mar 25 '15 at 03:17
  • *"I think there should be a better way where we can write the event handling for the parent control (in this case the Form) and then whenever a child control value gets changed, it will trigger even handler declared with the form"* - Only if you want to write it. – MadProgrammer Mar 25 '15 at 03:20
  • Yes, I don't know how. I want to accomplish this without declaring any events for the controls. Possible or not? – Sanone Mar 25 '15 at 03:23
  • At the end of the day, no. What you can do is make use the available [`InputVerifier`](http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html) and some clever coding to produce the effect you might be after, for [example](http://stackoverflow.com/questions/25274566/how-can-i-change-the-highlight-color-of-a-focused-jcombobox/25276658#25276658) – MadProgrammer Mar 25 '15 at 03:24
  • What I would consider doing is writing a "validation model" or "manager" which is tied to the `InputVerifier` API which allows to be notified when a field is been "tested" for validity. This would alert the model/manager which could then perform other checks. I'd also be very careful about wrapping all your validation into a single "check point", as this becomes very complex and difficult to manage, but that's me – MadProgrammer Mar 25 '15 at 03:27

0 Answers0