开发者

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

开发者 https://www.devze.com 2023-01-20 10:03 出处:网络
Is this always true? new JTextField().getDocument() instanceof PlainDocument B开发者_高级运维ecause I have read many examples of PlainDocument where they always create a new PlainDocument and then

Is this always true?

new JTextField().getDocument() instanceof PlainDocument

B开发者_高级运维ecause I have read many examples of PlainDocument where they always create a new PlainDocument and then assign it to a JTextField, e.g. here.


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

-> Yes is the answer.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消