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,
textField
field 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. SoTimer
class solved the problem:Now Dialog window (parent) if
setVisible(true);
shows as newly created - without blinking textFields and focused right. Finally.. :)