|
How to find size of string drawn on a component |
|
|
"I am drawing a string [via g.drawString()] on a JComponent and I want to enlarge the component if needed, so that it doesn't clip the string. I can't figure out how to find the size of the string that will be drawn, to resize the component. Any ideas?"
You can use the following code segment to obtain the width of the String drawn. someFont variable is the font used by the component and someString is the string drawn:
FontMetrics fm = someComponent.getFontMetrics(someFont);
int width = fm.stringWidth(someString);
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.