Search code examples
javaswingjtextpane

Detecting number of lines in JTextPane


My program fills a JTextPane with various messages, some extending the JTextPane to 2 lines to fit the text, and some only one line. I want the pane to always be two lines. Is there a way to return the amount of lines that text in a JTextPane is currently occupying?


Solution

  • Is there a way to return the amount of lines that text in a JTextPane is currently occupying?

    Check out Text Utilities, which is not the same as the link provided in the comment.

    You should be able to use the getWrappedLines(...) method.