Add Close event for Shell window : Shell Event « SWT « Java Tutorial






import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class ShellWindowCloseEvent {

  public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.addListener(SWT.Close, new Listener() {
      public void handleEvent(Event event) {
        System.out.println("cose");
      }
    });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
}








17.5.Shell Event
17.5.1.Shell Events
17.5.2.Change the default behavior of shellsChange the default behavior of shells
17.5.3.Add Close event for Shell window
17.5.4.Add Resize listener to ShellAdd Resize listener to Shell