Java examples for 2D Graphics:Font
Get Font Information
import java.applet.Applet; import java.awt.Font; import java.awt.Graphics; public class Main { public void paint(Graphics g){ Font currentFont = g.getFont(); String fontName = currentFont.getName(); int size = currentFont.getSize(); int style = currentFont.getStyle(); String fontStyle = ""; /*from w ww . ja v a 2 s .c o m*/ if( (style & Font.BOLD) == Font.BOLD) fontStyle = "Bold"; if( (style & Font.ITALIC) == Font.ITALIC) fontStyle = "Italic"; if( (style & Font.PLAIN) == Font.PLAIN) fontStyle = "Plain"; String family = currentFont.getFamily(); System.out.println("Font Name: " + fontName); System.out.println("Font size: " + size); System.out.println("Font Family: " + family); System.out.println("Font Style: " + fontStyle); } }