0

How can I add just numbers betwwen 0 and 255 in a FormattedTextField in Java?

I tried this way :

private JFormattedTextField text4;
//...
text4= new JFormattedTextField(paymentFormat);
    text4.getValue();
    text4.setColumns(3);
    try {
        MaskFormatter mask = new MaskFormatter("###");
        mask.install(text4);
    } catch (ParseException ex) {
       System.out.print("Valoarea nu e corecta");
    }

and it doesn`t work...

Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
  • Is it possible to be more specific on _"it doesn't work"_? – Thomas Mar 07 '13 at 13:52
  • IT DISPLAYS : "THE VALUE IS NOT CORRECT" JUST AFTER I COMPILE THE PROGRAM. MOREOVER, THIS SOLUTION COULD WORK FOR EVERY NUMBER BETWEEN 0 AND 999... –  Mar 07 '13 at 15:18
  • See [this answer](http://stackoverflow.com/a/13424140/1076463), and simply adjust the `java.text.Format` to only accept values between 0 and 255 – Robin Mar 07 '13 at 16:25
  • sorry, Thomas, I forgot the caps lock on:( –  Mar 07 '13 at 18:29
  • thank you , I solved it with InputVerifier. –  Mar 07 '13 at 21:12
  • and is there any possibility not to let me type incorrect values(letters) instead of returning an exception if i type a letter? –  Mar 08 '13 at 11:29

1 Answers1

1

there are two ways

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319