I am learning java swing. There is an editable JComboBox for selecting different depths of water and a JTextField to accept mobile number. My question is how can I restrict the user to enter only digits in these two fields and also, how to limit the maximum number of character inputs like not more than 10 for the mobile number? Are methods available for these requirements or I need to define them of my own?
Thanks in advance for your help.
I am learning java swing. There is an editable JComboBox for selecting different depths
Share
Use a
JFormattedTextFieldsomething like:This automatically has the properties you want it will only accept digits in a specified format
Have a look at the docs too for more info: JFormattedTextField