package snippet; import java.util.*; import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; public class ShellOrderSnippet { public static void main(String[] args) { final Display display= new Display(); final Shell shell= new Shell(display); shell.setText("Main"); shell.setBounds(100, 100, 200, 160); shell.setLayout(new GridLayout()); Label temp= new Label(shell, SWT.NONE); shell.open(); for (int i= 0; i < 3; i++) { Shell child= new Shell(shell, SWT.SHELL_TRIM); child.setText("Child " + i); Rectangle bounds= shell.getBounds(); bounds.x+= 20 * (i + 1); bounds.y+= 20 * (i + 1); child.setBounds(bounds); child.open(); child.addShellListener(new ShellAdapter() { public void shellClosed(ShellEvent e) { display.asyncExec(new Runnable() { public void run() { Shell[] subShells= shell.getShells(); System.out.println(Arrays.asList(subShells)); if (subShells.length > 0) { subShells[subShells.length - 1].setActive(); } } }); } }); if (temp != null) { temp.dispose(); temp= null; } } while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }