• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Limiting character count on each line of JTextArea

 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic