File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Limiting character count on each line of JTextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Limiting character count on each line of JTextArea" Watch "Limiting character count on each line of JTextArea" New topic
Author

Limiting character count on each line of JTextArea

Anand Loni
Ranch Hand

Joined: Jan 20, 2006
Posts: 150
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


~ Anand,
SCJP 1.5, SCWCD 1.5
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10175
    
    8

Cant you use the JTextArea(int rows,int columns) constructor and then set the line wrap and wrap style word to true?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Anand Loni
Ranch Hand

Joined: Jan 20, 2006
Posts: 150
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

Joined: Sep 20, 2005
Posts: 862
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?


bitguru blog
 
 
subject: Limiting character count on each line of JTextArea
 
Similar Threads
Insertion in JTextArea
JTextArea + ActionListener
JTextArea Problem
scrolling downwards in a jtextarea
TextArea wrap