Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JFormatField + MaskFormatter + AnnoyingFeature!!  RSS feed

 
H Melua
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • 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
 
Brian Cole
Author
Ranch Hand
Posts: 949
1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you very much Brian
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!