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(String mask) throws ParseException 

Source Link

Document

Creates a MaskFormatter with the specified mask.

Usage

From source file:org.biojava.bio.view.MotifAnalyzer.java

private JTextField getMotifWidth() {
    if (motifWidth == null) {
        try {// w ww .j  a v a 2s  .c o m
            motifWidth = new JFormattedTextField(new MaskFormatter("##"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        motifWidth.setText("12");
    }
    return motifWidth;
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * @param mask/*  w w  w .  ja  v a  2  s . c  o m*/
 * @return
 */
public static MaskFormatter createFormatterMask(final String mask) {
    MaskFormatter maskFormatter = null;
    try {
        maskFormatter = new MaskFormatter(mask);

    } catch (java.text.ParseException exc) {
        System.err.println("formatter is bad: " + exc.getMessage());
        System.exit(-1);
    }
    return maskFormatter;
}

From source file:wicket.util.convert.MaskConverter.java

/**
 * Construct.// w  w  w . ja  v  a  2s.c  o  m
 * 
 * @param mask
 *            The mask to use for this converter instance
 * @param type
 *            The type to convert string values to. WARNING: adding anything
 *            that implements charsequence here will probably not have the
 *            desired effect as then only {@link #toString(Object)} will be
 *            called. Consider wrapping your string value in a custom class
 *            so that conversion will be triggered properly. That class
 *            should have a public constructor with a single string
 *            argument. That constructor will be used by
 *            {@link MaskFormatter} to construct instances.
 * @see MaskFormatter
 */
public MaskConverter(String mask, Class type) {
    try {
        maskFormatter = new MaskFormatter(mask);
        maskFormatter.setValueClass(type);
        maskFormatter.setAllowsInvalid(true);
        maskFormatter.setValueContainsLiteralCharacters(true);
    } catch (ParseException e) {
        throw new WicketRuntimeException(e);
    }
}