views:

29

answers:

2

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.

+1  A: 

Unless a class which implements the Document interface is passed to the JTextField constructor, the createDefaultModel() method is called, which does create a PlainDocument.

RD
+1  A: 

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

-> Yes is the answer.

Albert