How do I get text width and height in Swing/AWT?

by ice1000   Last Updated December 07, 2017 06:13 AM

I'm making a game engine based on Java Swing and I wonder if I can get the text width/height.

Say, what I have is:

  • the text string
  • the font and text size (the Font object)

What I've done is:

  • g.drawString(...)

What I want to know is:

  • the width/height of the text that displayed on the screen
Tags : java swing

Related Questions

How to detect if a key is held?

Updated June 19, 2017 00:13 AM

Making Video Games In pure Java, where to go?

Updated October 08, 2018 14:13 PM