Get font family name in Java

Description

The following code shows how to get font family name.

Example


  /*from ww w.j a  v  a 2  s.  c o  m*/
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.JFrame;

public class Main extends JFrame {

  public static void main(String[] a) {
    Main f = new Main();
    f.setSize(300, 300);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
  }

  public void paint(Graphics g) {
    Font f = g.getFont();
    String fontFamily = f.getFamily();

    g.drawString(fontFamily, 4, 16);
  }
}




















Home »
  Java Tutorial »
    Graphics »




Animation
BufferedImage
Color
Font
Gradient
Graphics Settings
Image
Mouse Draw
Print
Shape
Text
Transform