public static void configureNumericFormattedTextField(@NotNull JFormattedTextField textField){
  NumberFormat format=NumberFormat.getIntegerInstance();
  format.setParseIntegerOnly(true);
  format.setGroupingUsed(false);
  NumberFormatter numberFormatter=new NumberFormatter(format);
  numberFormatter.setMinimum(0);
  textField.setFormatterFactory(new DefaultFormatterFactory(numberFormatter));
  textField.setHorizontalAlignment(SwingConstants.TRAILING);
  textField.setColumns(4);
}

public static void configureNumericFormattedTextField ( @ NotNull JFormattedTextField textField ) { NumberFormat format = NumberFormat . getIntegerInstance ( ) ; format . setParseIntegerOnly ( true ) ; format . setGroupingUsed ( false ) ; NumberFormatter numberFormatter = new NumberFormatter ( format ) ; numberFormatter . setMinimum ( 0 ) ; textField . setFormatterFactory ( new DefaultFormatterFactory ( numberFormatter ) ) ; textField . setHorizontalAlignment ( SwingConstants . TRAILING ) ; textField . setColumns ( 4 ) ; }
it is your responsibility to set correct horizontal align ( left in case of ui designer )
