java, print in bold

前端 未结 2 1467
星月不相逢
星月不相逢 2020-12-02 01:50

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

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

System.         


        
相关标签:
2条回答
  • 2020-12-02 02:38

    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);
    
    0 讨论(0)
  • 2020-12-02 02:48

    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".)

    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.

    0 讨论(0)
提交回复
热议问题