开发者

How to reset a field in swing after dispose() is called

I have a JFrame and I have created an object to open it and close it all around my project. This means I am using only one object for that JFrame.

When I call dispose() method t开发者_StackOverflowo close that frame I expect it to be reset to a new JFrame on next setVisible(true) call. But i can still see the fields filled with value from the previous setVisible(true) call even after i called dispose() on closing it.

How do I flush the stored values from that frame so that I get a new form when i call setVisible(true)?


Try adding a WindowListener:

frame.addWindowListener(new WindowAdapter() {
    public void windowClosed(WindowEvent e) {
         MyJFrame frame = (MyJFrame) e.getSource();
         frame.someTextField.setText("");
         ...
    }
});

This isn't tested but should be close enough to get you started.


dispose() doesn't reset your components but you can create new JFrame manually:

previous.setVisible(false);
previous = new JFrame();
previous.setVisible(true);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜