Maximum length of JTextField and only accepts numbers?
问题 I want the user to input a maximum of 8 numbers as it is a field for Mobile number. This is my JTextField. txtMobile = new JTextField(); txtMobile.setColumns(10); txtMobile.setBounds(235, 345, 145, 25); add(txtMobile); While we're at it, how do I check for invalid characters like >> '^%$* in a JTextField ? 1)Maximum Length 2)Accepts only numbers 3)Check for invalid characters 4)Check if it's a valid email address Please help :D 回答1: You could use a JFormattedField , check out How to Use