I have added ComponentListener to JTextField parent like this:
parent.addComponentListener(new ComponentAdapter() {
@Override
public void componentHidden(ComponentEvent e) {
setText("");
}
});
So after parent becomes invisible, textField text is set to "". Everything works, but the problem is when I set parent to visible - for some milliseconds previous text of textField is displayed, and then field becomes empty. So it's not very nice..
Before setting the parent to invisible,
textFieldfield is settextField.setText(null);(no need to repaint), then the problem is with focus - it must be set to some initial component likepanel.requestFocusInWindow();. But the focus is not always set right in time. SoTimerclass solved the problem:Now Dialog window (parent) if
setVisible(true);shows as newly created - without blinking textFields and focused right. Finally.. :)