Creates Font - Java 2D Graphics

Java examples for 2D Graphics:Font

Introduction

The following snippet of code creates some Font objects:

Create serif, plain font of size 10

Font f1 = new Font(Font.SERIF, Font.PLAIN, 10);

Create SansSerif, bold font of size 10

Font f2 = new Font(Font.SANS_SERIF, Font.BOLD, 10);

Create dialog, bold font of size 15

Font f3 = new Font(Font.DIALOG, Font.BOLD, 15);

Create dialog input, bold and italic font of size 15

Font f4 = new Font(Font.DIALOG_INPUT, Font.BOLD|Font.ITALIC, 15);

To set the font for a Swing component, use its setFont() method.

JButton closeButton = new JButton("Close");
closeButton.setFont(f4);

Related Tutorials