you can use jformattedfieldtext and use maskformatter to give it a format to limit the number of characters, for example:
MaskFormatter formatter = null;
try {
formatter = new MaskFormatter("####"); //4 numbers only
} catch (java.text.ParseException exc) {
System.err.println("formatter is bad: " + exc.getMessage());
System.exit(-1);
}
JFormattedTextField jFormattedTextField = new JFormattedTextField(formatter);
good luck