1

How can I print a text on console with highlighted colour.

I found this link but this talks about printing text in colur and not highlighting it with another color.

Example:

enter image description here

Community
  • 1
  • 1
Tirthankar
  • 565
  • 1
  • 6
  • 10

1 Answers1

3

To switch on a yellow background (say), you need the escape sequence

java.lang.String("\033[43m");

Combine this with a black foreground to get what you want.

I'm getting the escape sequences from this Scala doc. Although it's Scala doc it's relevant and applicable in Java. The Jansi library should handle this. See the 'background' references in the Ansi class.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440