Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java字体:一个特定字符的宽度使用了多少像素_Java - Fatal编程技术网

Java字体:一个特定字符的宽度使用了多少像素

Java字体:一个特定字符的宽度使用了多少像素,java,Java,我需要找出java中特定字符的宽度使用了多少像素——例如,字符“3”和“1”的宽度(以像素为单位) 有什么想法吗?在graphics中,您可以使用FontMetrics方法给出答案,如下所示: FontMetrics metrics = g.getFontMetrics(font); int width = metrics.stringWidth("3"); 我认为你需要给我们提供更多的背景。您试图在什么API下实现这一点,以及可能的复制目的是什么

我需要找出java中特定字符的宽度使用了多少像素——例如,字符“3”和“1”的宽度(以像素为单位)


有什么想法吗?

在graphics中,您可以使用FontMetrics方法给出答案,如下所示:

FontMetrics metrics = g.getFontMetrics(font);
int width = metrics.stringWidth("3");

我认为你需要给我们提供更多的背景。您试图在什么API下实现这一点,以及可能的复制目的是什么