Create font from true type font : Font « 2D Graphics GUI « Java

Create font from true type font


import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class Main {
  public static void main(String[] args) throws Exception {
    File f = new File("your.ttf");
    FileInputStream in = new FileInputStream(f);
    Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, in);
    Font dynamicFont32Pt = dynamicFont.deriveFont(32f);

    JLabel testLabel = new JLabel(dynamicFont.getName());
    JFrame frame = new JFrame("Font Loading Demo");


Related examples in the same category

1.Ascii font pattern
2.A cache of the dynamically loaded fonts found in the fonts directory
3.Load font from ttf file
4.Outline Font paintOutline Font paint
5.Font paintFont paint
6.Font DerivationFont Derivation
7.Font centeredFont centered
8.Font ListFont List
9.FontDemo lists the system fonts and provides a sample of each one(Have some problems)
10.Finds and displays available fonts
11.Obtain FontMetrics of different fonts
12.Draw font inside a Rectangle
13.Display font in a grid
14.Wrap string according to FontMetrics
15.Draw base line and enclosing line for a font
16.List all Fonts