How do I delete an object referenced by a dialog?

后端 未结 8 2436
独厮守ぢ
独厮守ぢ 2021-02-14 11:42

I created a dialog with a jpanel inside it, and that jpanel will be still referenced if I get rid of the dialog. I want to destroy that dialog and everything in it when I click

8条回答
  •  野性不改
    2021-02-14 12:37

    Answering the question(s) you posed in the comment:

    Once you have displayed a dialog:

    setVisible(true);
    

    you hide it by calling:

    setVisible(false);
    

    and then you must call:

    dialog.dispose();
    

    to make sure that all native GUI resources the dialog used get freed. Once you have done this, the garbage collector will clean up all of the objects once you no longer have any references to them.

提交回复
热议问题