Get font size in Java

Description

The following code shows how to get font size.

Example


import java.awt.Font;
import java.awt.Graphics;
/* w  ww .  j av  a  2  s. co m*/
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();
    int fontSize = f.getSize();

    g.drawString(fontSize+"", 4, 16);
  }
}




















Home »
  Java Tutorial »
    Graphics »




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