您可以使用JComponent#setForeground(Color) - 但不能使用JTextArea.它不是为此目的而设计的.而是使用JEditorPane或JTextPane.
在这些组件上,您还可以使用HTML标记,例如:
"<html>My text: <font color=\"blue\">" + myString + "</font></html>"
Run Code Online (Sandbox Code Playgroud)
你可以改变背景的中JTextArea使用的JTextArea#的setBackground(如果你的意思).