• Post Reply Bookmark Topic Watch Topic
  • New Topic

MaskFormatter automatically filling in the blanks  RSS feed

 
Janus Engstrøm
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi fellow ranchers,

I've got a formatted text field which I've instantiated like this:



The mask works splendidly, but it has an (to me, at least) annoying side effect: If the value in the text field isn't 4 digits long it's being padded with white spaces

I'd like the MaskFormatter stop doing that (or perhaps it's the JFormattedTextField being annoying?), but how?


Kind regards,

Janus
[ September 12, 2008: Message edited by: Janus Engstr�m ]
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never used the MaskFormatter class so this is just a guess based on the Javadoc. Try calling the MaskFormatter.setPlaceholder method with an empty String as a parameter.
 
Janus Engstrøm
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joanne,

Thanks for your reply!

I've already tried that option, but I think it's only for values inserted programmatically into the text field. At least it's not working, my formatted text field initially has the value of " " (4 white spaces).


Kind regards,

Janus
 
Janus Engstrøm
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Was thinking that it's probably the behavior a MaskFormatter should have, hence the name 'Mask'.

I found another solution by implementing my own Document:




Now I just have to figure out how to implement the MaskFormatters ability to convert lower-case to uppercase and the other way around...


Regards,

Janus
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll find the source code for MaskFormatter in a file called src.zip in your JDK installation directory.
 
Tom Pax
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A simple solution that works for me is:



Every time you focus the textfield the listener eliminates the blanks.

Ciao
Tom
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!