What is the Secret of Joy in Suffering?

You know complaining is completely counterproductive, but how do you follow the command to be joyful, even when you're really hurting?

In one sentence: "Jesus is far superior to everything that I have."

Philippians 3:8-10 (ESV)

Indeed, I count everything as loss because of the surpassing worth of knowing Christ Jesus my Lord. For his sake I have suffered the loss of all things and count them as rubbish, in order that I may gain Christ and be found in him, not having a righteousness of my own that comes from the law, but that which comes through faith in Christ, the righteousness from God that depends on faith— that I may know him and the power of his resurrection, and may share his sufferings, becoming like him in his death...