0

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?

Stepan Yakovenko
  • 7,404
  • 22
  • 105
  • 187
  • 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 Answers2

1

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

StanislavL
  • 56,113
  • 9
  • 64
  • 93
1

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

MadProgrammer
  • 336,120
  • 22
  • 219
  • 344