For example: I have an user that may be a minor. If he's a minor, the parent's name must be set. I have 3 situations:
- he's an adult. Panel state is valid. Ok and cancel button are active, no warning. All is good.
- he's an minor with an empty parent name. You get the red text warning (which is just Swing from my JPanel, no Platform stuff here) and the OK button is disabled. Noticed that ? This is where the isValid() does its work.
- he is a minor with a non-empty parent name. The OK button is enabled (isValid contribution) and no more red warnings (pure Swing code): Fun stuff no ?
The way this is doable is: just look at the TODOs.
- Implement the load() and store() methods in the generated Panel to have persistence.
- Implement the valid() method in the Panel. In my case is something as simple as
return adult || (!adult && parentName.getText().trim().length()>0);
- Then implement the final TODO from the constructor: listen to changes in form fields and call controller.changed() In my case I just call controller.changed() when the radio buttons are pressed and also in a DocumentListener for the text (to detect if the parent name changes and provide instant feedback).
And that was all it was needed. Now I have a simple, interractive with possible invalid states option panel.
If this was helpful for you then maybe you'll like reading the other NetBeans Platform-related posts.
Java-loving consulting services from Timisoara, Romania.