-3

I want to determine if JTextField.getText() contains only numbers between 0-9, where anything else is not accepted such as letters and other characters. What's a good way to do this? thanks.

user2052855
  • 23
  • 1
  • 2
  • 5

1 Answers1

1

If you are using NetBeans to build your GUI, you just need to put regular JTextFields in your GUI and in the creation code, you will specify the constructor of IntegerField.

OR

Use JFormattedTextField capabilities.

numberField = new JFormattedTextField(NumberFormat.getInstance());.

Have a look at example(http://docs.oracle.com/javase/tutorial/uiswing/components/formattedtextfield.html).

Arjun Chaudhary
  • 2,373
  • 2
  • 19
  • 36