Solved

Counting Lines

Posted on 2002-07-15
2
185 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Securing Jmx Console and web console 2 64
eclipse formatting 6 68
Java Loop 6 48
eclipse shortcuts 9 45
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

943 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

10 Experts available now in Live!

Get 1:1 Help Now