Java Font.getSize()
Syntax
Font.getSize() has the following syntax.
public int getSize()
Example
In the following code shows how to use Font.getSize() method.
// w w w. j a v a 2 s.co 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.setVisible(true);
}
public void paint(Graphics g) {
Font f = g.getFont();
int fontSize = f.getSize();
int fontStyle = f.getStyle();
String 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);
}
}
Home »
Java Tutorial »
java.awt »
Java Tutorial »
java.awt »