0

I'm writing a Sudoku board in Java and opted to use the JFormattedTextField class for the board cells because I can have a control about the input with providing a correct DecimalFormat object.

My question is, what String should I use in the constructor of the DecimalFormat so that it would represent a pattern of a single digit between 1-9.

Alternatively, is there a better class(es) to use for that purpose?

Thanks

Amihai Zivan
  • 173
  • 4
  • Hi, please look this existing post : http://stackoverflow.com/questions/8637792/how-to-set-jformattedtextfield-so-it-only-allows-2-numbers – Julien Gauthier Dec 22 '16 at 16:52

1 Answers1

0
    String pattern = "#";
    DecimalFormat decimalFormat = new DecimalFormat(pattern);
    decimalFormat.setMaximumIntegerDigits(1);      
    String format = decimalFormat.format(number);
Khalil M
  • 1,788
  • 2
  • 22
  • 36