Search code examples
javaswingdocumentjtextfield

java: is the default document of a JTextField always a PlainDocument?


Is this always true?

new JTextField().getDocument() instanceof PlainDocument

Because I have read many examples of PlainDocument where they always create a new PlainDocument and then assign it to a JTextField, e.g. here.


Solution

  • Ah, just checked out. The documentation says yes. The empty constructor always uses createDefaultModel() and createDefaultModel() always returns a PlainDocument.

    -> Yes is the answer.