package test; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class Test2 { static boolean c1True = true; public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout(1, false)); Composite parent = new Composite(shell, SWT.NONE); // parent.setLayout(new FillLayout()); final Composite c1 = new Composite(parent, SWT.NONE); c1.setBackground(display.getSystemColor(SWT.COLOR_RED)); c1.setBounds(0, 0, 500, 500); final Composite c2 = new Composite(parent, SWT.NONE); c2.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); c2.setBounds(0, 0, 500, 500); Button b = new Button(shell, SWT.PUSH); b.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { if (c1True) { c2.moveAbove(c1); } else { c1.moveAbove(c2); } c1True = !c1True; } @Override public void widgetDefaultSelected(SelectionEvent e) { // TODO Auto-generated method stub } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }