How to change the font color of a JTextArea?

4

Throughout the internet I just found people wanting to know how to style part of the text and being "redirected" to JTextPane , so there are no answers to my question out there.

So there goes: I have a JTextArea in a JFrame how can I change the font color of the entire text of JTextArea ?

Current code:

import javax.swing.*;
import java.awt.*;    
class MyFrame extends JFrame{
    private JTextArea text;
    public MyFrame(){
        text = new JTextArea();
        text.setBackground(Color.BLACK);
        text.setFont(new Font("Consolas", Font.BOLD, 14));
        //Trocar cor da fonte para branco aqui...
    }
}
    
asked by anonymous 17.10.2014 / 15:52

1 answer

3

JTextArea inherits from JComponent , which automatically wins setForeground , so you can do for example:

jTextArea.setForeground(Color.RED);
jTextArea.setForeground(new java.awt.Color(r, g, b));
    
17.10.2014 / 16:10