How can I apply a different color to text that a user adds to a JTextPane?

Sandip Chitale

You can let the user enter text in default color. You could call the

public void insertString(int offset,
                         String str,
                         AttributeSet a)
                  throws BadLocationException

API to add your text passing the right AttributeSet (font, color) for your text.