Limit characters in a JFormattedTextField
问题 I'm trying to restrict the characters' number in a JFormattedTextField. I'm using a regular expression to validate the field but I need to limit the input too. I tried DocumentFilter and PlainDocument but it didn't work. Here is my code: public class UsingRegexFormatter { public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JFormattedTextField formattedField = new JFormattedTextField(new RegexFormatter("[0-9]+([,\\.][0-9]+)*"