java中字符串的字体设置 [英] Font settings for strings in java
问题描述
我可以在java中为字符串设置字体属性。
Can I set font properties for a string in java.
推荐答案
对象( JLabel
等),而不是在 String
本身。
Font properties are set on the Font object in the GUI object that you are using (JLabel
, etc), not on the String
itself.
编辑:
如果您要向控制台添加格式, String
本身。为了让我的输出是粗体,我需要做以下:
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");
(char)27
序列后, [
后面是一组;
用于不同格式类型的分隔值(见下文) m
。你需要玩弄这个。在我的Mac,命令提示符继续以粗体,因为我没有重置正常( [0m
)在我退出之前。
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
这篇关于java中字符串的字体设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!