How to get the correct String width from FontMetrics in JAVA

前端 未结 3 1968
南笙
南笙 2021-01-01 03:05

I calculate the width of a string by using the stringWidth(\"str\") method on the FontMetrics object. This method only gives me the width from the

3条回答
  •  Happy的楠姐
    2021-01-01 03:39

    you need a graphics object.

    graphics.setFont(font);

    int lenghtgraphics.getFontMetrics(graphics.getFont()).stringWidth(value);

提交回复
热议问题