How to calculate the font's width?

后端 未结 6 1541
眼角桃花
眼角桃花 2020-12-15 09:52

I am using java to draw some text, but it is hard for me to calculate the string\'s width. for example: zheng中国... How long will this string occupy?

6条回答
  •  无人及你
    2020-12-15 10:18

    Take a look at this great presentation, especially "Text Measurement" part. It explains available sizes and their uses: Advanced Java 2D™ topics for Desktop Applications.

    Some more information in Java2D FAQ: What is the difference between logical, visual and pixel bounds?

提交回复
热议问题