How to get JTextArea restricted

Hi All,

Can anybody help me out for this one. its urgent.

I've used a JTextarea in my project. I want that user should get restricted to type just 60 characters in a line and can type only 36 lines of text in that. he must get a msg Box if he tries to type more than the one specified and should not be able to type.

Thanks in advance,

New_logical_developer

[389 byte] By [logical_new_developera] at [2007-11-27 11:46:40]
# 1

Do you want it coded for you, or is there a question you want to ask about your code?

The first choice is unlikely to create any replies.

ChuckBinga at 2007-7-29 18:08:51 > top of Java-index,Java Essentials,Java Programming...
# 2

A document listener?

TuringPesta at 2007-7-29 18:08:51 > top of Java-index,Java Essentials,Java Programming...
# 3

Hi,

I'm new to Java. so can anybody help me with the code?

thanks in advance

logical_new_developera at 2007-7-29 18:08:51 > top of Java-index,Java Essentials,Java Programming...
# 4

> Can anybody help me out for this one. its urgent.

As it's so urgent I'll help you help you a week next caturday. How's that for you?

c0demonk3ya at 2007-7-29 18:08:51 > top of Java-index,Java Essentials,Java Programming...
# 5

Use setColumns() from JTextArea it set max no. of columns that it can have

AmitChalwade123456a at 2007-7-29 18:08:51 > top of Java-index,Java Essentials,Java Programming...
# 6

i've already tried this one but it doesn't restrict user to input more than the specified characters but it just sets the width of the display area of JTextArea.

logical_new_developera at 2007-7-29 18:08:51 > top of Java-index,Java Essentials,Java Programming...
# 7

In the future, Swing related questions should be posted in the Swing forum.

Each criteria on its own is easy to implement. However combining the two is where it gets difficult and I don't have a solution.

For example what happens if you have two line of 45 characters each and then the use tries to remove the new line character between the two lines. Now the total line lenght would be 90 characters which is invalid. So do you prevent the user from removing the end of line character or do you manually split the lines into one of 60 and the other of 30?

Also what happens if you have 50 characters of text and the user tries to paste some text containing 30 characters. Do you ignore the last 20 characters or manually create a new line with the 20 characters.

Or maybe your requirement is that you want the lines to "wrap" at 60 characters so you don't have a physical new line character in the file.

So basically we can't really help since you requrement is not a simple as you think.

However, the general solution would probable be to use a DocumentFilter, which is explained in the Swing tutorial on "Text Component Features":

http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html#filter

camickra at 2007-7-29 18:08:51 > top of Java-index,Java Essentials,Java Programming...