• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

count letters of a string entered from the JTextArea

i am wanting to count letters of a String entered from the JTextArea
0
MarcusDHooks
Asked:
MarcusDHooks
  • 3
2 Solutions
 
CEHJCommented:
int letterLength = textArea.getText().getLength();
0
 
CEHJCommented:
Sorry

int letterLength = textArea.getText().length();
0
 
CEHJCommented:
Or better

int letterLength = textArea.getDocument().getLength();
0
 
objectsCommented:
textfield.getDocument().addDocumentListener(new DocumentListener()
{
 public void changedUpdate(DocumentEvent e) {}
 public void insertUpdate(DocumentEvent e)
 {
    count();
  }

 public void removeUpdate(DocumentEvent e)
 {
    count();
  }

 void count()
 {
     Document doc = event.getDocument();
    int count = doc.getLength();
     System.out.println("No chars="+count);
  }
});
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now