Jtextfield formatting with CPF mask

Asked

Viewed 276 times

0

Would anyone know how to answer me as I leave a field JTextField with the CPF mask. I think you can do this by setting a Document to the JTextField, but I don’t know how to do it. Someone could help me?

Note: I wish to use a JTextField and not a JFormatedTextField.

  • 2

    Take a look http://answall.com/questions/41083/m%C3%A1scara-Monet%C3%A1ria-para-jtextfield

  • You are using which IDE?

1 answer

2


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

I suggest you extend the class javax.swing.Plaindocument, then overwrite the method insertString(int offs, String str, Attributeset a).

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

At this link (+ that) you can find some examples of how to create a Document for Jtextfield with entry restrictions.

Note: You may have to overwrite the remove(int offset, int length) method as well;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.