[英]How to determine font width in pixels in Swing application for remote desktop
我创建了一个swing应用程序,我通过putty远程调用它。 在实际的系统中,字体大小适合下面的代码,但在远程控制台我没有得到字体的大小。
我使用以下代码来查找当前环境的字体大小(以像素为单位):
FontMetrics metrics = control
.getFontMetrics(control.getFont());
int hgt = metrics.getHeight();
int adv = metrics.stringWidth();
但是当从putty远程调用时,上面的代码不起作用。
我使用了http://docs.oracle.com/javase/tutorial/2d/text/measuringtext.html中的方法
有谁知道如何处理它。
感谢帮助。
.stringWidth
缺少String
参数。 该方法接受String
并使用给定的Font
测量它,从而得到给定文本的advance width 。 您应该重新阅读您链接的文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.