Listener listener = new Listener () {
public void handleEvent (Event e) {
switch (e.type) {
case SWT.Dispose:
Shell shell = parent.getShell ();
shell.removeListener (SWT.Deiconify, shellListener);
shell.removeListener (SWT.Iconify, shellListener);
parent.setVisible(false);
EventQueue.invokeLater(new Runnable () {
public void run () {
frame.getToolkit().removeAWTEventListener(awtListener);