Sign in to follow this  

[java] Getting lines in JTextArea

This topic is 2551 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there anyway I can figure out the number of lines of text on a JTextArea if the lines there are because I set the line wrap property to true? The getLineCount() function only seems to get the number of lines that are due to a "\n" character.

Am I going to have to figure that out myself or is there some kind of function that can help me?

Share this post


Link to post
Share on other sites
This is the most useful example I have found.

It requires the use of "javax.swing.text.Utilities", which I didn't know existed until now :)

You just need to modify the example a bit. Instead of building a new String, you'll want to increment and return a counter every time you find a "soft" new line.

Share this post


Link to post
Share on other sites

This topic is 2551 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this