How to change the font color of a Jtextarea?

Asked

Viewed 2,723 times

5

All over the internet I just found people wanting to know how to stylize part of the text and being "redirected" to JTextPane, then there are no answers to my question around.

So there you go: I got one JTextArea in a JFrame how can I change the font color of any text in the 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...
    }
}

1 answer

4


Jtextarea inherits from Jcomponent, that automatically wins setForeground, therefore, you can do for example:

jTextArea.setForeground(Color.RED);
jTextArea.setForeground(new java.awt.Color(r, g, b));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.