Font settings for strings in java

后端 未结 4 1740
轮回少年
轮回少年 2020-12-10 21:44

Can I set font properties for a string in java.

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 22:15

    Font properties are set on the Font object in the GUI object that you are using (JLabel, etc), not on the String itself.

    EDIT:

    If you want to add formatting to your console, you will have to embed the formatting within the String itself. In order to get my output to be bold, I needed to do the following:

     System.out.println((char)27 +"[1m testing bold");
    

    The (char) 27 is an escape sequence, the [ is followed by a set of ; separated values for different formatting types (see below), followed by an m. You will need to play around with this. On my Mac, the command prompt continued in bold as I didnt reset to normal ([0m) before I exited.

    This info, by the way, was lifted from here. some attributes:

    0 Normal (clear all)
    1 bold
    2 dim
    4 underline
    5 blink
    7 reverse
    8 blank
    9 overstrike
    22 normal intensity (cancel bold and blank)
    24 underline off
    25 blink off
    27 reverse off
    28 blank off
    29 overstrike off
    30 black
    31 red
    32 green
    33 yellow
    34 blue
    35 magenta
    36 cyan
    37 white
    40 black background
    41 red background
    42 green background
    

提交回复
热议问题