How can I Keep Cows from Running Away?
Cows (along with all passive mobs) have no AI other than "wander". They will blissfully stumble head-first into lava if given the chance.
As of Beta 1.6.6, there is no way to encourage Passive Mobs to stick around; even "happy" cows will disappear into the ether if you wander far enough away that the chunk gets unloaded from Memory.
On the other hand, fence-escaping can simply be halted by making the fence taller.
Edit:
As of Beta 1.8, passive mobs no longer despawn. If you fence a cow, sheep, or pig, and keep them safe from wolves / aggressive mobs, they should stay fenced-in indefinitely.
You can prevent the cows bouncing by simply making the fence taller. Their pathing AI seems to think they can make what should be a one block jump; however, the fences' unusual collision check ends up blocking them. Thus, they start bouncing whenever they wander near.
You can't make them stay though, they will despawn eventually (as of 1.6.6).