Example usage for javax.swing.text MaskFormatter MaskFormatter

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

Introduction

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

Prototype

public MaskFormatter() 

Source Link

Document

Creates a MaskFormatter with no mask.

Usage

From source file:com.haulmont.cuba.desktop.gui.components.DesktopTimeField.java

public DesktopTimeField() {
    UserSessionSource uss = AppBeans.get(UserSessionSource.NAME);

    digitWidth = getDigitWidth();//from  w w  w . ja  v a2  s.  co  m

    timeFormat = Datatypes.getFormatStringsNN(uss.getLocale()).getTimeFormat();
    resolution = DateField.Resolution.MIN;
    formatter = new MaskFormatter();
    formatter.setPlaceholderCharacter('_');
    impl = new FlushableFormattedTextField(formatter);
    FieldListener listener = new FieldListener();
    impl.addFocusListener(listener);
    impl.addKeyListener(listener);

    setShowSeconds(timeFormat.contains("ss"));
}

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

/**
 * This method initializes jNombreTarjetaTextField   
 *    //from  w  ww  . j av  a2 s  .c o  m
 * @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;
}