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


Java Thread.sleep() VS Get last and current time

Updated April 08, 2017 15:13 PM