Java tutorial
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import javax.swing.JFormattedTextField; import javax.swing.text.DefaultFormatterFactory; import javax.swing.text.MaskFormatter; public class Main { public static void setFoneMask(JFormattedTextField textField) { try { MaskFormatter mask = new MaskFormatter("(##) ####-####"); textField.setFormatterFactory(new DefaultFormatterFactory(mask)); } catch (ParseException e) { e.printStackTrace(); } } }