There are several places in mods where you may want to display text and you probably want to control the formatting (like the color, font, etc.). For example, you may create a GUI for a custom lore book, or you might want to display some response to a custom command.
Example #1: Making Rainbow-Colored Text
Here is a method I use to create rainbow colored text. Hopefully it is self explanatory. Basically I count through the letters in the input string and cycle through the colors of the rainbow.
Example #2: Dynamic Formatting (Gold Shimmer Effect)
It is possible to have the formatting change over time to create an "animation" effect. In this example, the text will be a gold color that will have a shimmer move through the text occasionally.
Create Web-Linked Clickable Text
Thanks to Choonster for this tip.
You can either use ITextComponent.getStyle().setClickEvent on the text component to make the whole text clickable with whatever action you want or you can use ForgeHooks.newChatWithLinks, which will parse a String for URLs and make them clickable.