Solved

Counting Lines

Posted on 2002-07-15
2
184 Views
Last Modified: 2010-03-31
How do I count the number of lines in a JTextArea component using a JButton to tell it when to update the count?

0
Comment
Question by:Cosmo439
  • 2
2 Comments
 
LVL 7

Accepted Solution

by:
tomboshell earned 50 total points
ID: 7156443
Have the button retrieve the value returned by JTextArea's 'getLineCount()' method, which returns an int.  

Otherwise, a work around could be first call the Document, then get the elements and send it to an ElementIterator and count.

Document doc = txtA.getDocument();
int ctr=0;
ElementIterator elmIt=new ElementIterator(doc.getDefaultRootElement());
while((elmIt.next() != null)){
   ctr++;
}

something like the code above would be a work-around, but try the getLineCount() method first if it is a JTextArea
0
 
LVL 7

Expert Comment

by:tomboshell
ID: 7168750
Thanks and I hope that it was a help!
Tom
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now