Java examples for Swing:JFormattedTextField
Use JFormattedTextField to set a limit on the number of characters that can be entered in a field
import java.text.ParseException; import javax.swing.JFormattedTextField; import javax.swing.text.MaskFormatter; public class Main { public static void main(String[] args) { try {// w w w .j av a2 s . c o m JFormattedTextField twoCharField = new JFormattedTextField( new MaskFormatter("**")); } catch (ParseException e) { e.printStackTrace(); } } }