I want to know if there is any function or something so can change my text color like: System.out.println("hi") the text "hi" will be in red and same as others texts thk
Asked
Active
Viewed 146 times
1
-
2Not without using some sort of GUI. Just plain printing does not involve colors. – arshajii Oct 25 '13 at 13:32
-
3If you happen to be using an IDE like Eclipse, and you specifically want red... `System.err.println("hi")`. – Russell Zahniser Oct 25 '13 at 13:33
-
3@RussellZahniser That's a bad idea... printing to the error stream should only be done if there is an *error*. – arshajii Oct 25 '13 at 13:34
-
1@arshajii do you think OP wants to write a serious programm? ... i would say in this case it's ok – Philipp Sander Oct 25 '13 at 13:35
-
4@PhilippSander I disagree; we should instill best practices from an early stage. – arshajii Oct 25 '13 at 13:36
-
1System.err.println has nothing to do with red...It prints to a totally different output stream, and the IDE happens to print that stream in red. It's a behavior of the environment, not the language. – Ian McLaird Oct 25 '13 at 13:39
-
Possible duplicate: http://stackoverflow.com/questions/5762491/how-to-print-color-in-console-using-system-out-println – Ian McLaird Oct 25 '13 at 13:43
-
Use System.err.println and don't listen @arshajii – hellzone Oct 25 '13 at 13:45
-
1@hellzone Making an unsubstantiated claim like that doesn't mean much. In any case, it's a terrible idea for a variety of reasons. As Ian McLaird rightfully pointed out, it's not guaranteed to work everywhere. Moreover, it's just a bad practice to print to the error stream arbitrarily, as I mentioned in a comment to a since-deleted answer below. – arshajii Oct 25 '13 at 13:53
-
1Why would you assume that he's *not* writing a serious program? It's clearly serious enough that he wants to provide color-coded output. This is a serious question, with a somewhat tricky real answer (see the other question I linked to). – Ian McLaird Oct 25 '13 at 13:59
1 Answers
0
Unfortunately there is no, because System.out
uses plain standard system output.
If you would like to color some text, then use some GUI, using for example Swing
.

Eel Lee
- 3,513
- 2
- 31
- 49
-
If the terminal you're running on supports ANSI escape sequences, you have more options: http://stackoverflow.com/questions/5762491/how-to-print-color-in-console-using-system-out-println – Ian McLaird Oct 25 '13 at 13:53