Gripens may not be the best (and nowadays not the most modern) jets, but that was one of the design features Sweden took as a reason to develop their own jet.
The theoretical possibility of getting invaded and losing their primary infrastructure (being a rather neutral country up to their application for NATO last year...) was a reason they wanted a jet with good short-field performance that can be easily supplied by dispersed small bases.
They basically started designing a jet 50 years ago exactly for today's Ukraine scenario. Being invaded and only getting limited international support because neighbours (and NATO members) would stop at measures that would make them a direct participant in that war.