Stepan Yakovenko
Stepan Yakovenko

Reputation: 9206

How to measure height of text that is presented by single String and limited by width, so it'd be multiline?

I am going to draw multiline text. Text is limited by width, it wouldn't fit there, so I'd like to how many lines would be there, i.e. I need height of rectangle. I have font variable in Java. How can I do that?

Upvotes: 0

Views: 578

Answers (2)

MadProgrammer
MadProgrammer

Reputation: 347184

Have a look at Measuring Text, in particular Drawing Multiple Lines of Text

Upvotes: 1

StanislavL
StanislavL

Reputation: 57381

Try this http://java-sl.com/tip_text_height_measuring.html it works if you reflect the text in JEditorPane/JTextPane.

Upvotes: 1

Related Questions