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
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.