• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JFormatField + MaskFormatter + AnnoyingFeature!!

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I dont understand the behaviour of JFormattedTextField!
I want a field that only accepts binary of length 12... and thats all i want!! i dont want extra annoying features!

The problem i'm having now is..I've got 2 fields



and when i run my program, i enter the values in both.. and lets say i press enter and it resets the fields to display nothing, i do the same again but this time i decide not to enter data in bField (although i jumped to it using the tab button after aField)... what bugs me is that after i leave the bField (using the Tab button again) it displays the previous value i have entered in that field!! Now i want it to just leave it blank the way it is!!
i know i cant have empty field but i dont mind it placing blank characters, but not the previous value!

Thanks
HannaH
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by H Melua:
it resets the fields to display nothing,



How are you doing this?

It sounds like you may be doing something like setText(""), which
will clear the field visually but not change the result of getValue().

i do the same again but this time i decide not to enter data in bField (although i jumped to it using the tab button after aField)... what bugs me is that after i leave the bField (using the Tab button again) it displays the previous value i have entered in that field!! Now i want it to just leave it blank the way it is!!



Perhaps setFocusLostBehavior(JFormattedTextField.COMMIT)
would be closer to what you want. Set that way, when the field loses
focus with displayed text that is invalid, the invalid text will remain but
getValue() will continue to return the last valid value.

The default is COMMIT_OR_REVERT, which replaces the displayed text
with that of the last valid value. This would seem to be what you are
complaining about.
[ November 14, 2007: Message edited by: Brian Cole ]
 
H Melua
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much Brian
 
These are the worst of times and these are the best of times. And this is the best tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic