Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color of java console output

I was wondering if there is someway for me to set the color of the text that I output to the console in Java. It does not matter if it is system specific as the program will only be run on my Windows 7 x64 laptop.

This question: Change color in java eclipse console was asked several weeks ago and had a good solution(by @VonC) to a similar problem however it only addressed the issue inside eclipse.

Can the same effect be achieved if I execute my program from the command line? and if so how?

like image 520
chandsie Avatar asked May 07 '11 19:05

chandsie


People also ask

How do you color text in Java?

Syntax: System. out. println(ANSI_COLORNAME + "This text is colored" + ANSI_RESET);

How do I change the color of my console in Eclipse?

To change a color, click on the colored button next to the desired console output type and select a new color. Check this box if want to have SVN messages sent to the Eclipse console.


1 Answers

thy this.... furthermore read http://jansi.fusesource.org/

public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_BLACK = "\u001B[30m";
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_YELLOW = "\u001B[33m";
public static final String ANSI_BLUE = "\u001B[34m";
public static final String ANSI_PURPLE = "\u001B[35m";
public static final String ANSI_CYAN = "\u001B[36m";
public static final String ANSI_WHITE = "\u001B[37m";
like image 122
a.s.p. Avatar answered Oct 15 '22 07:10

a.s.p.