Estoy tratando de hacerlo poniéndole un DocumentFilter al Document del JTextField, pero no me funciona...
También hay algo que no entiende ese código, ¿para qué sirve los parámetros FilterBypass y off?
Código (java) [Seleccionar]
JtextField txtNumero1 = new JTextField();
final PlainDocument doc = new PlainDocument();
doc.setDocumentFilter(new DocumentFilter() {
public void insertString(FilterBypass fb, int off, String str, AttributeSet a)
throws BadLocationException
{
if (fb.getDocument().getLength() + str.length() <= 2) {
fb.insertString(off, str, a);
}
}
});
txtNumero1.setDocument(doc);
También hay algo que no entiende ese código, ¿para qué sirve los parámetros FilterBypass y off?