While David does not take action against Shimi ben Gera, who cursed him in his flight from Avshalom, during his reign, he does tell Shlomo to 'take care' of Shimi ben Gera, toward the end of his life. Shlomo essentially puts Shimi on a sort of house arrest, which he violates, resulting in his death, (See Kings I chapter 2 for the whole incident). He has Yoav, (who disobeyed him at least once from what I remember by killing Avshalom, Samuel II chapter 18), dealt with in a similar way, kings I ch 2 also).
Yosef, when kissing his brothers after hugging and kissing Binyamin, cries, (Genesis 45:15). Yonatan ben Uziel,(ibid) says that he cried because he saw that the brothers would be spread amongst the nations. Yosef also knew that the Egyptian exile was in full swing. I have heard, though I lack a distinct source that our egyptian exile, and perhaps subsequent exiles where at least a partial result of Yosef's sale at the hands of his brothers, and had Yosef held out a little longer, they may not have needed to happen, or perhaps not to the same extent that they did. I will try to find a clear source, but I am assuming that Yosef knew that the brothers' actions toward would have consequences.
I would argue that, in situations where a king is affronted while he isn't really or completely a king, he may be allowed to forgive this affront, or may be required to, but he is still not able to completely let the offending party off the hook. So Yosef forgave the brothers both because he was not yet fully a king when they had sold him, (though he had had the dreams and Reuven had lost the firstborn rights already, presumably passing them to him, see Yonatan ben Uziel genesis 49:3, and because he knew through prophecy that they would in later generations suffer for what they had done.