Can we combine 2 font styles together in Java?

user633784 picture user633784 · Aug 2, 2011 · Viewed 23.2k times · Source

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?

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());

Answer

trashgod picture trashgod · Aug 2, 2011

Yes, the style parameter is seen as a bitmask:

new Font("Verdana", Font.BOLD + Font.ITALIC, 12)