DisposeListenerWithShell.java Source code

Java tutorial

Introduction

Here is the source code for DisposeListenerWithShell.java

Source

import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class DisposeListenerWithShell {
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new GridLayout());

        // Create the child shell and the dispose listener
        final Shell childShell = new Shell(shell);
        childShell.addDisposeListener(new DisposeListener() {
            public void widgetDisposed(DisposeEvent event) {
                // When the child shell is disposed, change the message on the main shell
                System.out.println("Dispoase");
            }
        });
        childShell.setLayout(new FillLayout());
        childShell.setText("little brother");
        childShell.open();

        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }
}