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
You meant "how" to destroy it? There is no way to destroy an object explicitly in Java. garbage collector in Java automatically reclaims the memory occupied by it If there is no reference of the same exists.
"but I create dialog with jpanel inside it, and that jpanel will be still referrenced. I want to destroy that dialog when click my own button "Cancel"
Just try setting that JPanel object to null or call the dispose method on it if that is available.