title: how can i count lines in JTextArea?
body: <p>I tried using linewarp, but it seems that it won't work. I need to make something that counts the lines of the text you insert in a JTextArea.</p>
  
  <p>Here is my code, until now I am having so much trouble. My program can now count 50 words and when ok is fired it counts the words and the letters and every 50 words it puts a sign of &lt;&lt;50>> or &lt;&lt;100>> or....:</p>
  
  <pre><code>package wordscount;
  
  import java.awt.BorderLayout;
  import java.awt.Dimension;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JOptionPane;
  import javax.swing.JScrollPane;
  import javax.swing.JTextArea;
  import javax.swing.Timer;
  
  /**
   *
   * @author Shady Kamal
   * 
   */
  
  public class WordsCount{
  
  boolean isword;
  boolean working;
  int words = 0;
  int charsa = 0;
  int max = 3000;
  JTextArea text = new JTextArea(70, 70);
  JTextArea wordsText = new JTextArea();
  JTextArea charsText = new JTextArea();
  JFrame frame = new JFrame("Fast Reading 50 words - Made by Shady Kamal ©");
  JButton launch = new JButton("Start");
  JButton fullScreenButton = new JButton("Full Screen");
  JLabel charsLabel = new JLabel();
  JLabel wordsLabel = new JLabel();
  String atext;
  Dimension screenDimension= new Dimension();
  Timer timer;
  
  
  
  public WordsCount(){
  
      wordsText.setText("Words: " + "\n");
      wordsText.setEditable(false);
      wordsText.setEnabled(true);
      charsText.setText("Letters: " + "\n");
      charsText.setEnabled(true);
      charsText.setEditable(false);
      wordsText.setSize(10, 2);
      charsText.setSize(10, 2);
  
      frame.setSize(700, 700);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      launch.addActionListener(new ActionListener(){
  
      @Override
      public void actionPerformed(ActionEvent e) {
  
          int wordsSize = 0;
          words = 0;
          atext = text.getText();
          charsa = atext.length();
          launch.setName("Start - Pressed");
  
          if(words &lt;= 49){
              launch.setEnabled(true);
          }else{
              launch.setEnabled(false);
          }
  
  
          for (int i = 0; i &lt; charsa; i++) {
  
              wordsSize++;
  
              if ( Character.isLetter(atext.charAt(i)) == false ){
                     isword = false;
                 }else if (i == 0){
                     isword = true;
                 }else if ( Character.isLetter(atext.charAt(i-1)) ){
                     isword = false;
                 }else if ( atext.charAt(i-1) == '\'' &amp;&amp; i &gt; 1 &amp;&amp; 
                            Character.isLetter(atext.charAt(i-2)) ){
                     isword = false;
                  }else{
                     isword = true;
                  }
              if (isword){
                  words++;
                  if(words == 50 || words == 50*2 || words == 50*3 || words == 50*4 
                          || words == 50*5 || words == 50*6 || words == 50*7 
                          || words == 50*8 || words == 50*9 || words == 50*10 
                          || words == 50*11 || words == 50*12 || words == 50*13 
                          || words == 50*14 || words == 50*15 || words == 50*16 
                          || words == 50*17 || words == 50*18 || words == 50*19 
                          || words == 50*20 || words == 50*21 || words == 50*22 
                          || words == 50*23 || words == 50*24 || words == 50*25 
                          || words == 50*26 || words == 50*27 || words == 50*28 
                          || words == 50*29 || words == 50*30 || words == 50*31 
                          || words == 50*32 || words == 50*33 || words == 50*34 
                          || words == 50*35 || words == 50*36 || words == 50*37 
                          || words == 50*38 || words == 50*39 || words == 50*40 
                          || words == 50*41 || words == 50*42 || words == 50*43
                          || words == 50*44 || words == 50*45 || words == 50*46 
                          || words == 50*47 || words == 50*48 || words == 50*49 
                          || words == 50*50 || words == 50*51 || words == 50*52
                          || words == 50*53 || words == 50*54 || words == 50*55
                          || words == 50*56 || words == 50*57 || words == 50*58
                          || words == 50*59 || words == max){
                      text.insert(" &gt;&gt;" + words + "&lt;&lt; ", wordsSize);
                  }
                 }
                }
                System.out.println("Chars: " + charsa);
                System.out.println("Words: " + words);
                wordsText.setText("Words: \n" + words);
                charsText.setText("Letters: \n" + charsa);
  
              }
         });
  
      charsLabel.add(charsText);
      wordsLabel.add(wordsText);
      frame.add(text, BorderLayout.CENTER);
      frame.add(wordsText, BorderLayout.EAST);
      frame.add(charsText, BorderLayout.WEST);
      frame.getContentPane().add(new JScrollPane(text),BorderLayout.CENTER);
      frame.add(launch, BorderLayout.SOUTH);
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
  
  }
  
  public static void main(String[] args) {
  
      JOptionPane.showMessageDialog(null, ""
              + "                                Instructions: \n"
              + "_________________________________________\n"
              + "Just paste text right here in the TextBox\n"
              + "and click the \"Start\" button when your'e ready\n"
              + "the program will do the rest.\n"
              + "PAY ATTENTION!\n"
              + "1)It works only up to 3,000 words Just for \n"
              + "preventing bugs and lags and Making it smoothier and easier to run\n"
              );
  
      new WordsCount();
  
  }
  
  }
  </code></pre>