tested code is recommended as followed
//close the Dialog
if( e.getSource() instanceof JButton )
// Make sure this event was launched from a Button.
{
Container c = ((JButton)(e.getSource())).getParent();
// get the container for this button.
while( (c.getParent() != null)&&(!(c instanceof JDialog)) )
{
c = c.getParent();
}
// loop until you get the top level frame/dialog...
// you may want to play with this some... I know that
// problems may arise in
Applets, since the top level
// frame is the browser, and Dialogs may present a
// problem too, since Frames may be their parents...
// experiment with calls...
if( c instanceof JDialog )
// If the top level container you finally found was a
// dialog...
{
JDialog d = ( JDialog )c;
// Now you have a reference to the Dialog, and can
// manipulate it however you want...
d.dispose();
}
}