Solved

Counting Lines

Posted on 2002-07-15
2
191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

688 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