I have an AWT modal dialog
public class d extends java.awt.Dialog {...
On the dialog frame, using netbeans gui designer I put dialog then panel then button. I am trying to close the dialog by pressing the button. I am not interested in System.exit(0).
The netbeans generator created
private void jButtonCloseActionPerformed(java.awt.event.ActionEvent evt){
I think I should call dispose in that function, however when called it disposes the dialog but dialog thread never ends.
I have the following handler working when window is closed by default dialog close button
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
Window window = SwingUtilities.getWindowAncestor(e.getComponent());
window.dispose();
}
});
and the above is working fine, i.e. thread ends.
I could use the same approach in the jButtonCloseActionPerformed but I don't know how can I get window object.
How can I achieve that? Any other good solution is very welcomed as well.
I will appreciate your help very much.