| Author |
InputVerifier and JFormattedTextField Problem :(
|
|
| Steve Webb 2004-04-27, 10:54 am |
| Hi,
I've got a JFormattedTextfield which I've set a formatter, enter key
listener and InputVerifier on and it all works fine when the user
enters data and pressed enter or tabs out of the field. The checks are
made fine. However if the program itself calls setValue() or setText()
on the field the InputVerifier gets called and then fails. The problem
seems to be that even though the text is now shown in the field the
call to getText in the verifier returns an empty string !!! The
verifier is shown below, any ideas ?
class ssccVerifier extends InputVerifier {
public ssccVerifier() {
}
public boolean verify(JComponent input) {
if(!(input instanceof JFormattedTextField))
return true;
JFormattedTextField jftf = (JFormattedTextField)input;
NumberFormatter formatter =
(NumberFormatter)jftf.getFormatter();
if(formatter == null)
return true;
try {
String content = jftf.getText();
Long v = (Long)formatter.stringToValue(content);
jftf.setValue(v);
clearError();
return true;
} catch (ParseException pe) {
jftf.selectAll();
displayError("Valid SSCC is between " +
formatter.getMinimum() + " and " + formatter.getMaximum());
}
return false;
}
}
| |
|
| try this (i haven't tested this)
String content = jftf.getText();
if (content != null && !content.equals("")) {
Long v = (Long)formatter.stringToValue(content);
jftf.setValue(v);
}
clearError();
return true;
Regards,
Will
| |
|
| Thanks for that Will. I'd already added something similar as a work around so great minds think
alike. The problem I have though is that when the setText() or setValue() is used the value passed
is from another system which could pass invalid data so the idea was that the normal validation on
the field would either flag a problem up or not.
Any idea's why setValue() and/or setText() on a JFormattedTextField with an InputValidator causes
the getText() not to function as expected in the veryify routine ? Strikes me its some kind of Java
bug on the face of it.
"Will" <will@coderight.nl> wrote in message news:f5a0996b.0404271131.753baf70@posting.google.com...
> try this (i haven't tested this)
>
> String content = jftf.getText();
> if (content != null && !content.equals("")) {
> Long v = (Long)formatter.stringToValue(content);
> jftf.setValue(v);
> }
> clearError();
> return true;
>
> Regards,
> Will
| |
|
| > Any idea's why setValue() and/or setText() on a JFormattedTextField with an InputValidator causes
> the getText() not to function as expected in the veryify routine ? Strikes me its some kind of Java
> bug on the face of it.
I think after setValue/setText you should do a commitEdit()
Will
author of JForm
jform.coderight.nl
"Webby" <steve@swebb99.fs2.com> wrote in message news:<c6mmkt$tma$1@news.freedom2surf.net>...[color=darkred]
> Thanks for that Will. I'd already added something similar as a work around so great minds think
> alike. The problem I have though is that when the setText() or setValue() is used the value passed
> is from another system which could pass invalid data so the idea was that the normal validation on
> the field would either flag a problem up or not.
>
> Any idea's why setValue() and/or setText() on a JFormattedTextField with an InputValidator causes
> the getText() not to function as expected in the veryify routine ? Strikes me its some kind of Java
> bug on the face of it.
>
>
> "Will" <will@coderight.nl> wrote in message news:f5a0996b.0404271131.753baf70@posting.google.com...
| |
|
| Ok Will I'll try that tomorrow and see what happens.
Thanks
Steve
"Will" <will@coderight.nl> wrote in message news:f5a0996b.0404281055.8e9ca65@posting.google.com...[color=darkred]
causes[color=darkred]
Java[color=darkred]
>
>
> I think after setValue/setText you should do a commitEdit()
>
>
> Will
> author of JForm
> jform.coderight.nl
>
>
> "Webby" <steve@swebb99.fs2.com> wrote in message news:<c6mmkt$tma$1@news.freedom2surf.net>...
passed[color=darkred]
on[color=darkred]
causes[color=darkred]
Java[color=darkred]
news:f5a0996b.0404271131.753baf70@posting.google.com...[color=darkred]
|
|
|
|