Java FontMetrics.charWidth(int codePoint)
Syntax
FontMetrics.charWidth(int codePoint) has the following syntax.
public int charWidth(int codePoint)
Example
In the following code shows how to use FontMetrics.charWidth(int codePoint) method.
/*from w w w. j a v a2 s . co m*/
import java.awt.FontMetrics;
import javax.swing.JFrame;
public class Main {
public static void main(String args[]) {
JFrame f = new JFrame("JColorChooser Sample");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300, 200);
f.setVisible(true);
FontMetrics metrics = f.getFontMetrics(f.getFont());
int widthX = metrics.charWidth((int)'C');
System.out.println(widthX);
}
}
Home »
Java Tutorial »
java.awt »
Java Tutorial »
java.awt »