Java JTextfields [duplicate]
问题 This question already has answers here : Is there any way to accept only numeric values in a JTextField? (19 answers) Closed 4 years ago . Just a quick question, How do i ensure my JtextField only accepts numeric values? I want it to to diplsy an error message if the user entered anything else thank you 回答1: You can use a JFormattedTextField. Construct it using a NumberFormatter and it will only accept numbers. The JFormattedTextField has a bunch of configurable options that let you decide