twisty
Posts: 22
Nickname: twisty
Registered: Nov, 2002
|
|
Re: Masking in Java
|
Posted: Nov 9, 2002 10:19 PM
|
|
I presume that your trying to create something like a password field, or something similar? If your using 1.4, its a simple matter of creating a JFormattedTextField with a MaskFormatter.
MaskFormatter maskFormatter = new MaskFormatter("####-####");
JFormattedTextField jftf= new JFormattedTextField(maskFormatter);
In the example above, the user is presented with a textfield that only allows numbers to be entered (____-____). Some other mask charachters are: ? - letter A - number/letter H - hexadecimal L - lowercase U - uppercase * - anything ' - escape charachter
In earlier versions of swing you can extend the PlainDocument class so that you can then use the setDocument method for your textfield to use your custom PlainDocument. If you don't know how to do this, feel free to ask.
|
|