Search code examples
javaswingoverridingjtextarea

Override JTextArea.getDocument.remove()?


Okay, I want to override JTextArea's Document's remove method, I can't figure out what class to extend. I can't extend Document cause it's a interface, and that also means it must not be the document that JTextArea creates. So how exactly can I easily override my JTextArea's document's remove method?


Solution

  • The default Document of a JTextArea is PlainDocument, as mentioned in createDefaultModel(). Here is a simple example of overriding insertString() in PlainDocument.