I created a JTextField (either with setting the text after the creation or in the constructor). After that I added a Document (setDocument) to the textfield and wondered why the text value of JTextField was empty.
Example:
JTextField field = new JTextField();
field.setText(textValue); // or instead setting the text in the constructor
field.setDocument(new TestDocument());
// text is no empty
Setting the document before the text fixes this entirely. I just wondered why this happens. Is it because the previously set text wasn't handled according to document?