I'm attempting to create a JFormattedTextField that will accept only a
certain set of characters, but there is not a limit on the length of
the string. I have put together a MaskFormatter like this (pardon any
typos, I'm having to type it in from scratch):
JFormattedTextField myFormattedTextField = new JFormattedTextField();
MaskFormatter mask = null;
try {
mask = new
MaskFormatter("***************************************************************");
// yes, I know this has a length limit, but it's long enough
} catch (ParseException e) {}
mask.setPlaceholder("");
mask.setPlaceholderCharacter(' ');
mask.setValidCharacters"a really long string with all my valid
characters);
mask.setAllowsInvalid(false);
mask.install(myFormattedTextField);
myFormattedTextField.setFormatter (mask);
When I run this, sometimes it rejects invalid characters, and other
times it allows them to be typed. I cannot figure out the logic of when
it does and does not - sometimes I initalize it to a valid string,
other times leave it blank, but this doesn't seem to have a bearing on
anything. Also, sometimes it's backfilled with spaces and sometimes
it's not. This is just not a hard thing to do, surely, I hope I am
missing something simple.
Thanks in advance for any pointers.
Janene
jonck@vanderkogel.net - 20 Nov 2005 23:33 GMT
> When I run this, sometimes it rejects invalid characters, and other
> times it allows them to be typed.
I have no idea what could be causing these symptons, though I'm sure
if you post a SSCCE (http://www.physci.org/codes/sscce.jsp) we'll be
able to get to the bottom of it.