Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set String's font size, style in Java using the Font class?

Tags:

java

fonts

Suppose I have a String, "Hello World". I want to change the style of this string to a BOLD font, and set the size of all the characters from 12 to 18 [pt]. After that I want to use this string in a JLabel and JButton. How can I do that?

like image 363
Jay Avatar asked May 17 '12 06:05

Jay


1 Answers

Font myFont = new Font("Serif", Font.BOLD, 12);, then use a setFont method on your components like

JButton b = new JButton("Hello World");
b.setFont(myFont);
like image 114
Petr Mensik Avatar answered Oct 13 '22 19:10

Petr Mensik