Example usage for javax.swing.text MaskFormatter setAllowsInvalid

List of usage examples for javax.swing.text MaskFormatter setAllowsInvalid

Introduction

In this page you can find the example usage for javax.swing.text MaskFormatter setAllowsInvalid.

Prototype

public void setAllowsInvalid(boolean allowsInvalid) 

Source Link

Document

Sets whether or not the value being edited is allowed to be invalid for a length of time (that is, stringToValue throws a ParseException).

Usage

From source file:Main.java

MaskFormatter createFormatter(String format) {
    MaskFormatter formatter = null;
    try {/*from w w  w . j a  v  a  2s  .c o  m*/
        formatter = new MaskFormatter(format);
        formatter.setPlaceholderCharacter('.'/*or '0' etc*/);
        formatter.setAllowsInvalid(false); // if needed
        formatter.setOverwriteMode(true); // if needed
    } catch (java.text.ParseException exc) {
        System.err.println("formatter is bad: " + exc.getMessage());
    }
    return formatter;
}

From source file:es.mityc.firmaJava.libreria.pkcs7.ValidaTarjeta.java

/**
 * This method initializes jNombreTarjetaTextField   
 *    //from   w w  w.  j  a va 2s .c om
 * @return javax.swing.JTextField   
 */
private JFormattedTextField getJNombreTarjetaTextField() {
    if (jNombreTarjetaTextField == null) {

        // El nombre de la tarjeta solo acepta letras y nmeros
        // Se agrega la barra baja como separador
        MaskFormatter formato = new MaskFormatter();
        formato.setValidCharacters(CARACTERES_VALIDOS);
        formato.setAllowsInvalid(false);
        try {
            formato.setMask(MASK);
        } catch (ParseException e) {
            // Nunca ocurre
        }

        jNombreTarjetaTextField = new JFormattedTextField(formato);
        jNombreTarjetaTextField.setFocusLostBehavior(javax.swing.JFormattedTextField.COMMIT);
    }
    return jNombreTarjetaTextField;
}