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?
Asked
Active
Viewed 573 times
0
-
are you using monospaced fonts? if so, you can look at your wrapper that how many characters on line 1 appears. then you can split your whole text to that number. this may give you the line numbers. – Muhammet Can Nov 26 '12 at 06:54
2 Answers
1
Try this http://java-sl.com/tip_text_height_measuring.html
it works if you reflect the text in JEditorPane/JTextPane
.

StanislavL
- 56,971
- 9
- 68
- 98
1
Have a look at Measuring Text, in particular Drawing Multiple Lines of Text

MadProgrammer
- 343,457
- 22
- 230
- 366
-
There's a related `TextLayout` example [here](http://stackoverflow.com/a/8282330/230513). – trashgod Nov 26 '12 at 11:06