What could cause painful testicular swelling to come and go?

See urologist. See a urologist, but i think that herniation and or strangulation of the vascular elements in the testicular sac may be 2 reasons.
Hydrocele. Most common on and off testicular swelling is from a hydrocele, a fluid filled sac that communicates with the abdomen and shifts fluids back and forth. The other problem may be a varicocele which is a collection of veins that get more swollen the more active a man is and the longer in the day he's on his feet.