Formatting JTextField with CPF Mask

0

Would anyone know how to respond to me as I leave a JTextField field with the CPF mask. I think you can do this by setting Document to JTextField , but I do not know how to do it. Could someone help me?

Note: I want to use JTextField and not JFormatedTextField .

    
asked by anonymous 01.07.2015 / 21:56

1 answer

2

@fbarros you can do implement the Document interface and setar in JTextField.

I suggest that you extend the javax.swing.PlainDocument class, then override the insertString method (int offs, String str, AttributeSet a).

In this method, treat String str. It is what you should treat which characters are accepted or not. Its value is what is being entered into the JTextField before it even appears.

On this link (#

Note: You may have to override the remove (int offset, int length) method too;

    
01.07.2015 / 22:46