[英]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.