File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Limiting character count on each line of JTextArea

 
Anand Loni
Ranch Hand
Posts: 150
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to limit 80 characters on each line in JTextArea. I have set my own document on JTextArea and I am overriding insertString method to check length. But I am unable to do this.

Please help me in this issue.

Thanks,
Anand
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cant you use the JTextArea(int rows,int columns) constructor and then set the line wrap and wrap style word to true?
 
Anand Loni
Ranch Hand
Posts: 150
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No this doesn't work for me.

I want to limit characters on a line to 80 and after that only '\n' (Enter) is accepted and control goes to next line. If no '\n' after 80 characters then control remains on the same line itself.
 
Brian Cole
Author
Ranch Hand
Posts: 886
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anand Loni:
I want to limit 80 characters on each line in JTextArea. I have set my own document on JTextArea and I am overriding insertString method to check length. But I am unable to do this.


This approach should be workable. (You probably also want to override the replace() method.)

Why don't you show us the insertString() code so we can analyze what went wrong?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic