How to get the width and height of a character? Source: chinaitlab.com 2003-9-30 16:22:00 ChinaitLab new logo officially launched, freshly baked! How to get the width and height of a character? The gitHeight (), charwidth () or StringWidth () method provided by the FontMetrics object can be used to obtain the height and width of the display of a character or a string. For example, in Graphics G:
String info = "test string" .FontMetrics metrics = getFontMetrics (g.getfont ()); int Height = metrics.getHEight (); int width = metrics.StringWidth (info); For details on these methods, please refer to the FontMetrics class API documentation.