Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use colours in console output in Scala or Java?

How to use colours in console output in Scala or Java?

like image 683
Ivan Avatar asked Sep 08 '10 04:09

Ivan


Video Answer


2 Answers

Try...

scala> Console.BLUE
res0: java.lang.String =

OK, well, the text has gone blue. Honest!

scala> Console.YELLOW_B
res2: java.lang.String =

And you can see the background is, um, yellow.

like image 185
oxbow_lakes Avatar answered Oct 15 '22 13:10

oxbow_lakes


Sample code from JavaWorld

import java.awt.Color;
import enigma.console.*;
import enigma.core.Enigma;
public class Main
{
    public static void main(String[] args)
    {
        TextAttributes attrs = new TextAttributes(Color.BLUE, Color.WHITE);
        s_console.setTextAttributes(attrs);
        System.out.println("Hello World!");
    }
    private static final Console s_console;
    static
    {
        s_console = Enigma.getConsole("Hellow World!");
    }
}

Visit the above link for more details and approaches.

like image 24
pavanlimo Avatar answered Oct 15 '22 15:10

pavanlimo