fontMetrics.getStringBounds() is too small

J

Joana

hi gurus,

I want to drow a rectangle, where a certain stringer fits inside.
I compute the string size in such a way:

Frame frame // here are my component. In the component are rectangle & string
frame.pack();
Graphics g = frame.getGraphics();
FontMetrics fm = g.getFontMetrics();

Rectangle2D bounds = fm.getStringBounds();

If I draw the rectangle of the bounds-large, I see 2/3 the whole
string in the rectangle only.
Why?

thanks for any help!

best reagards,
Joana
 
P

Paul Lutus

Joana said:
hi gurus,

I want to drow a rectangle, where a certain stringer fits inside.
I compute the string size in such a way:

Frame frame // here are my component. In the component are rectangle &
string frame.pack();
Graphics g = frame.getGraphics();
FontMetrics fm = g.getFontMetrics();

Rectangle2D bounds = fm.getStringBounds();

If I draw the rectangle of the bounds-large, I see 2/3 the whole
string in the rectangle only.
Why?

Probably has something to do with your code, which only you can see.

Do not cross-post. Choose one group. Make one post.
 
J

Joana

Might it have something to do with the Frame borders?

no...
but thank you for your answer!
 
W

William Brogden

Joana said:
hi gurus,

I want to drow a rectangle, where a certain stringer fits inside.
I compute the string size in such a way:

Frame frame // here are my component. In the component are rectangle & string
frame.pack();
Graphics g = frame.getGraphics();
FontMetrics fm = g.getFontMetrics();

Rectangle2D bounds = fm.getStringBounds();

If I draw the rectangle of the bounds-large, I see 2/3 the whole
string in the rectangle only.

Which 2/3? Is it centered and cropped or only one end cropped.
What is your code to draw the String?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top