If that's all there was to it, then every star would constantly shrink,
and maybe wind up as a black hole. But that's not what happens.
Yes, gravity is constantly pulling all its particles together. But there's
something ELSE going on, that's pushing them APART. So the star has
a constant size for most of its life.
The OTHER thing that's going on is the nuclear fusion in the star's core ...
like millions of H-bombs all exploding at the same time, ALL the time.
That's where all of the sun's energy comes from, and that's what pushes
the sun's particles OUTward, against the gravity pulling them together.