Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2004

Tip: Looking for answers? Try searching our database.

InputVerifier and JFormattedTextField Problem :(

Thread view: 
Steve Webb - 27 Apr 2004 12:41 GMT
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;
       }
       
   }
Will - 27 Apr 2004 20:31 GMT
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
Webby - 27 Apr 2004 23:25 GMT
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.

> try this (i haven't tested this)
>
[quoted text clipped - 8 lines]
> Regards,
> Will
Will - 28 Apr 2004 19:55 GMT
> 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

> 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
[quoted text clipped - 17 lines]
> > Regards,
> > Will
Webby - 29 Apr 2004 21:12 GMT
Ok Will I'll try that tomorrow and see what happens.

Thanks

Steve

> > 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
[quoted text clipped - 27 lines]
> > > Regards,
> > > Will


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.