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

2
  • How does printing in a colour, and highlighting in a colour differ ? Commented Dec 13, 2012 at 11:29
  • @Brian Agnew : I have edited my question to add an image to clear the difference between colored text and highlighted text. Commented Dec 13, 2012 at 11:35

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.