Bonzo
|
Posted: March 26, 2010 16:59 by Bonzo
|
|
Hi, Firstly, some thanks: great library, cheers! I've had a good thrash about with the API and can't find a way of listening out for failed validations and their associated components e.g. when the validation of JTextField fails, I'd like to be notified of the problem and of the source object that generated it. The reason I want to do this is so that I can decorate the JTextField with a tooltip text describing the problem. I don't want a problem panel under my form. cheers, Bonzo |
Validation Events???
Replies: 6 - Last Post: April 16, 2010 00:56
by: Tim Boudreau
by: Tim Boudreau
showing 1 - 7 of 7
Bonzo
|
Posted: March 26, 2010 17:46 by Bonzo
|
|
OK, got it to do what I wanted to with a hack. There must be a better way! I subclassed JTextField and had it implement ValidationUI. I then set the tooltip to the message, or cleared it as appropriate, with the following methods: public void clearProblem() public void setProblem(Problem arg0) and, of course added the textfield to the validation group like so: validationGroup = ValidationGroup.create(myTextField); Any ideas for a better way??? |
hugoheden
|
Posted: March 26, 2010 21:55 by hugoheden
|
|
Hi Bonzo, Are you using ValidationAPI 0.4 (downloadable from http://kenai.com/projects/simplevalidation/downloads) or are you compiling from svn trunk? |
hugoheden
|
Posted: March 26, 2010 22:35 by hugoheden
|
|
Hmm, if the former, I don't think it's possible to do this in a non-hackish way. It is possible on the trunk however. If creating a new ValidationListener using the static ValidationListenerFactory.createValidationListener(), you'll pass a custom ValidationUI to that method. But if using the trunk you should see tooltips and icons displayed by default on each component containing an error. Just create a SwingValidationGroup, and add one or more UI-component/Validator-pair to it and you'll be allright -- something like this: SwingValidationGroup svg = SwingValidationGroup.create(); svg.add( myTextField, myValidator ); svg.add( otherTextField, otherValidator ); Warning though: I'm not sure how much the trunk will change before next release. |
Bonzo
|
Posted: March 29, 2010 09:38 by Bonzo
|
|
Hi, Many thanks for the reply. I'm not compiling from the trunk unfortunately. I haven't been getting the tooltips though, just the icons. Maybe it's because I'm using a heavilly customized JTextField subclass, which now I come to think about it, might be doing some tooltip shenannigans of it's own when there's not enough room to display the text. OK, I look forward to the next release, but until then will continue to hack. One further question if I may? Will the approach you describe that's currently only available on the trunk, allow me to detected JTextField events? The reason I ask is because with my 'hack' I show a discrete, floating error popup next to the text field when it has focus, and then lose it when focus is lost. cheers......... |
hugoheden
|
Posted: March 31, 2010 22:36 by hugoheden
|
|
Not sure, but I think what you want to do would be possible. For each JTextField, you will instantiate a ValidationListener (using a factory method conveniently provided by the library). With each such ValidationListener you will register your custom ValidationUI implementation. One such ValidationUI instance will -- via the setProblem/clearProblem methods -- get notified whenever there's a "validation event" (so to speak) in the corresponding JTextField. The ValidationUI instance should probably also implement FocusListener, and be registered to listen to focus events that happens on the JTextField. Thusly, the little ValidationUI object will get notified of all "validation events" and all FocusEvents. And since it'll probably have a reference to the JTextField in question, it should be able to show the pop-up whenever suitable. Does this sound reasonable? Does it make any sense at all? That error pop-up sounds cool btw, you should stick around and create a little demo for us when next release is out the door We're planning (or at least I am ) an API (ComponentDecorator stuff) for being able to more easily customize what ValidationUI:s will be used application wide, for each specific ValidationGroup and for each specific JComponent. It'd be interesting to see whether your use-case can benefit from that API. |
Tim Boudreau
|
Posted: April 16, 2010 00:56 by Tim Boudreau
|
| FYI, there is a (not used yet) multiline-label that can display a problem tooltip/popup in source. Hasn't really been integrated yet, but it's there. |
showing 1 - 7 of 7
Replies: 6 - Last Post: April 16, 2010 00:56
by: Tim Boudreau
by: Tim Boudreau

We're planning (or at least I am 





