Java: How to I change the color of a specific line or row of string in a Text area?

Posted by Kevin on Stack Overflow See other posts from Stack Overflow or by Kevin
Published on 2011-01-11T03:46:59Z Indexed on 2011/01/11 3:53 UTC
Read the original article Hit count: 208

Filed under:
|
|

Hi all, the one way I could change the color is by setForground(). However when there are multiple lines of code it makes everything green or black. Is there another method or any way of solving this problem? Thanks!

int key = evt.getKeyCode();
    if (key == KeyEvent.VK_ENTER)
    {
       String tb1EnterdValue = tb1.getText().toString();
       if((tb1EnterdValue.equals("yes")) )
        {
            TextArea1.setForeground(Color.green);
    else
        {
              TextArea1.setForeground(Color.lightGray);
        }
       this.TextArea1.append(">"+tb1EnterdValue+newline);
       this.tb1.setText("");

© Stack Overflow or respective owner

Related posts about java

Related posts about textarea