Created
February 27, 2009 08:04
-
-
Save avh4/71348 to your computer and use it in GitHub Desktop.
Finding the width of rendered text - Wintriss Tech
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create the font and pass it to the Graphics context | |
g2.setFont(new Font("Monospaced", Font.BOLD, 24)); | |
// Get measures needed to center the message | |
FontMetrics fm = g2.getFontMetrics(); | |
// How many pixels wide is the string | |
int msg_width = fm.stringWidth(msg); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment