Reputation: 2037
So in JTextArea
there is a getLineCount()
is there something similar for JTextPane
, because I could find anything. Perhaps there is a different way of obtaining that? I want to get the number of currently existing lines.
Upvotes: 1
Views: 1795
Reputation: 9382
There is (as you noted) no built-in way to find the number of lines in a JTextPane
- this may be (although I see no official reference to support this) because of JTextPane
's ability to hold many different text styles in a single area, which would lead to some complications when finding the total number of lines.
You may be able to calculate the number of lines on your own, by keeping track of the text (and its style) that is presented inside of your JTextPane
- you can then use other methods (perhaps LineBreakMeasurer
(documentation here)) to calculate the number of lines for each piece of text, and then sum up the total.
Upvotes: 1