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 setValueMask(JFormattedTextField textField) { try { MaskFormatter mask = new MaskFormatter("R$ ###.##"); mask.setValidCharacters("0123456789"); mask.setPlaceholderCharacter('0'); textField.setFormatterFactory(new DefaultFormatterFactory(mask)); } catch (ParseException e) { e.printStackTrace(); } } }