I'm developing an application which requires that only 165 characters to be in the JTextArea. I've imposed that condition. I've used a static counter for counting number of characters entered in the textarea and also coded to handle the condition when user deletes any string from the text the counter must be incremented by considering length of the string selected.
However now I want to handle the condition when user performs 'cut' or 'paste' option by pressing 'Ctrl+X' and 'Ctrl+V'. I know that default methods from JTextComponent are inherited in JTextArea but I want to get the cut text and know the length of the cut text so as to decrement the counter maintained for characters and increment it while pasting by appropriate amount.
Create a DocumentFilter
and set it on a new PlainDocument
. Use this document to create the JTextArea
. (Or use the default document of the JTextArea, after casting to AbstractDocument).
See my answer here for a sample.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With