Font: getSize() : Font « java.awt « Java by API






Font: getSize()

  

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.setVisible(true);
  }

  public void paint(Graphics g) {
    Font f = g.getFont();
    String fontName = f.getName();
    String fontFamily = f.getFamily();
    int fontSize = f.getSize();
    int fontStyle = f.getStyle();

    String msg = "Family: " + fontName;
    msg += ", Font: " + fontFamily;
    msg += ", Size: " + fontSize + ", Style: ";
    if ((fontStyle & Font.BOLD) == Font.BOLD)
      msg += "Bold ";
    if ((fontStyle & Font.ITALIC) == Font.ITALIC)
      msg += "Italic ";
    if ((fontStyle & Font.PLAIN) == Font.PLAIN)
      msg += "Plain ";

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

   
    
  








Related examples in the same category

1.Font.PLAIN
2.Font.BOLD | Font.ITALIC
3.Font.BOLD
4.Font.ITALIC
5.Font.TRUETYPE_FONT
6.new Font(String name, int style, int size)
7.Font: createFont(int fontFormat, InputStream fontStream)
8.Font: createGlyphVector(FontRenderContext frc, String str)
9.Font: deriveFont(int style, float size)
10.Font: getFamily()
11.Font: getFontName()
12.Font: getLineMetrics(String str, FontRenderContext frc)
13.Font: getName()
14.Font: getStyle()
15.Font: getStringBounds(String str, FontRenderContext frc)