Get font name in Java
Description
The following code shows how to get font name.
Example
/*from w w 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 fontName = f.getName();
String msg = "Family: " + fontName;
g.drawString(msg, 4, 16);
}
}