One way to do this is to create your own document and override the insertString method. For example:
class CustomDocument extends PlainDocument {
@Override
public void insertString(int offset, String string, AttributeSet attributeSet)
throws BadLocationException {
super.insertString(offset, string, attributeSet);
}
}
This allows you to find out what is inserted and veto it if you want (without calling super.insertString). You can apply this document using this:
editorPane.setDocument(new CustomDocument());
source
share