我们可以将两种字体样式结合在一起吗? [英] Can we combine 2 font styles together in Java?
本文介绍了我们可以将两种字体样式结合在一起吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图改变 JLabel
的字体,所以它是 BOLD
和 ITALIC
,但似乎没有定义静态字段来这样做。我们怎样才能把两种样式结合起来,这样我们就可以有一个大胆的斜体字体了?
I am trying to change the font of a JLabel
so it is both BOLD
and ITALIC
, but it seems there's no static field defined to do so. How can we combine two styles so we can have a bold, italic font?
这段代码只用粗体显示,使用静态字段 BOLD
,但是没有为粗体和斜体定义的字段:
This code will do it with just bold by using the static field BOLD
, but there's no field defined for both bold and italic:
Font font = new Font("Verdana", Font.BOLD, 12);
label = new JLabel ("New Image") ;
label.setFont(font);
label.setForeground(Color.Gray.darker());
推荐答案
是的,style
参数被视为位掩码:
Yes, the style
parameter is seen as a bitmask:
new Font("Verdana", Font.BOLD + Font.ITALIC, 12)
这篇关于我们可以将两种字体样式结合在一起吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文