Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java, print in bold

How can I print output in bold in printf? "[1m testing bold" does not do anything.

String format = "%-20s %-15s %-20s %-15s %-10s";

System.out.printf(format, "Name", "Group_name", "Java_Prof_Level", "Cpr_Nr", "Gender", "[1m testing bold");
like image 365
Na Dia Avatar asked Mar 17 '15 21:03

Na Dia


People also ask

How do I print a bold string?

How do you change a string to bold in Python? Method 2: Using The ANSI Escape Sequence '\033[1m' The Most Pythonic way to print bolded text in Python is to enclose a given string s in the special escape sequence like so: print("\033[1m" + s + "\033[0m") .

How do you make text bold in JavaScript?

To create a bold text using JavaScript, use the bold() text. This method causes a string to be displayed as bold as if it were in a <b> tag.

How do you italicize text in Java?

println("\033[3mText goes here\033[0m"); Which will output italic text if your console supports it. You can use [1m for bold, etc.


2 Answers

You cannot print bold with Java System.out. It just streams to the standard output stream so, in principle, it is unformatted text only.

However, some software packages interpret special character sequences (the so-called ANSI escape sequences) to allow formatting.

Note that ANSI escape sequences start with an escape character, so you need to add that to your string also. (Try "\u001B[1m I am bold" or "\033[0;1m" + "I am bold".)

Most Unix terminals interpret ANSI escape sequences by default. In old DOS times, you needed to use ANSI.SYS for the escape sequences to work.

In Windows and the Eclipse terminal the codes do not work.

like image 73
Hoopje Avatar answered Oct 15 '22 05:10

Hoopje


This really depends on what kind of console is being used. For IDEs like Netbeans and Eclipse, I'm not sure if you can affect the font. But for most terminals, the following escape character works:

String textInBold = "Java_Prof_Level";
System.out.print("\033[0;1m" + textInBold);
like image 30
hrdasadia Avatar answered Oct 15 '22 03:10

hrdasadia