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
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.
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