tags:

views:

44

answers:

1

Hi,
I'm developing an application that requires a textarea to be used in which no. of characters are restricted to 165. I made an object of JTextArea with row & column no. 3,3 respectively but it didn't work as when I went on typing, the size of 'Textarea' went on increasing.How to restrict that? As I've used 'DocumentListener' for noting no. of characters typed,deleted,cut and pasted, I'm getting problem when suddenly the size of textarea is increased. Thank you!

A: 

What you want is a javax.swing.text.DocumentFilter. This enables you to filter changes to the Document which holds the underlying text of JTextArea. There are tutorials linked to from the class description for that and related classes.

The example here shows how to limit the number of characters in the document.

DJClayworth