Java examples for Swing:JFormattedTextField
To display 000-00-0000 in a SNN field, use '0' as a placeholder character for the mast formatter
import java.text.ParseException; import javax.swing.JFormattedTextField; import javax.swing.text.MaskFormatter; public class Main { public static void main(String[] args) { MaskFormatter ssnFormatter = null; JFormattedTextField ssnField = null; try {/*from w ww .j a v a2s .co m*/ ssnFormatter = new MaskFormatter("###-##-####"); ssnFormatter.setPlaceholderCharacter('0'); ssnField = new JFormattedTextField(ssnFormatter); } catch (ParseException e) { e.printStackTrace(); } } }