如何删除对话框引用的对象? [英] How do I delete an object referenced by a dialog?

查看:194
本文介绍了如何删除对话框引用的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在其中创建了一个带有jpanel的对话框,如果我删除了对话框,仍会引用jpanel。当我点击取消按钮时,我想破坏该对话框及其中的所有内容。如何删除对话框和jpanel?

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 a cancel button. How do I delete both the dialog and the jpanel?

推荐答案

回答您在评论

显示对话框后:

setVisible(true);

通过调用隐藏它:

setVisible(false);

然后你必须致电:

dialog.dispose();

以确保释放对话框使用的所有本机GUI资源。完成此操作后,垃圾收集器将在您不再引用所有对象时清理所有对象。

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.

这篇关于如何删除对话框引用的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆