How to count the number of lines in a JTextArea, including those caused by wrapping?

You can use LineBreakMeasurer Class.

The LineBreakMeasurer class allows
styled text to be broken into lines
(or segments) that fit within a
particular visual advance. This is
useful for clients who wish to display
a paragraph of text that fits within a
specific width, called the wrapping
width.LineBreakMeasurer implements the most commonly used line-breaking policy: Every
word that fits within the wrapping
width is placed on the line. If the
first word does not fit, then all of
the characters that fit within the
wrapping width are placed on the line.
At least one character is placed on
each line.

Leave a Comment