Java Swing Tutorial - Java Font.deriveFont(int style)








Syntax

Font.deriveFont(int style) has the following syntax.

public Font deriveFont(int style)

Example

In the following code shows how to use Font.deriveFont(int style) method.

import java.awt.Font;
import java.io.FileInputStream;
import java.io.InputStream;
//w w  w.  ja v  a2  s  .c  o m
public class Main {
  public static void main(String[] args) throws Exception{
    String fontFileName = "yourfont.ttf";
    InputStream is = new FileInputStream(fontFileName);

    Font ttfBase = Font.createFont(Font.TRUETYPE_FONT, is);

    Font ttfReal = ttfBase.deriveFont(Font.BOLD);
  }

}