James 1:2-4 My brethren, count it all joy when ye fall into divers temptations; Knowing this, that the trying of your faith worketh patience. But let patience have her perfect work, that ye may be perfect and entire, wanting nothing.
I used to say, "Don't ask God to give you patience because you will get a lot of trials instead!" But you know what? Patience can't be developed in any other way but through those things that cause us frustration and grief. If everything in our lives went along just like we planned it and nothing ever went wrong in our lives we would have no opportunity to learn patience.
In the verses above, when it says "...that ye may be perfect..." in the Greek it actually carries the meaning of being mature. So when our faith is tried, it is exercising our patience. We are to be joyful because God is giving us the chance to develop patience in our lives. If we don't fight against it, not only will patience be developed but we will grow into maturity.
I don't know what your particular trials are, whether it be pain, a wayward child, death or illness or financial difficulties, Scripture isn't saying for you to be happy go lucky in the face of difficulty, but it is saying that you can count it joy knowing that you have the opportunity to develop patience and maturity in godly character.
There is a difference between happiness and joy. Happiness is fleeting and depends on the circumstances, but joy is deep and abiding in the soul even in the face of difficulty because we know God is working all things together for our spiritual good and the spiritual good of others around us. Do you have this joy?