public class TestWidgetOrdering {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
final Composite holder = new Composite(shell, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, true).applyTo(holder);
holder.setLayout(new FillLayout());
final Label label1 = new Label(holder, SWT.NONE);
label1.setText("1");
final Label label2 = new Label(holder, SWT.NONE);
label2.setText("2");
Label label3 = new Label(holder, SWT.NONE);
label3.setText("3");
Label label4 = new Label(holder, SWT.NONE);
label4.setText("4");
Label label5 = new Label(holder, SWT.NONE);
label5.setText("5");
Button button = new Button(shell, SWT.PUSH);
button.setText("Move");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
label1.moveBelow(label2);
holder.layout();
}
});
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
One potential solution is to use Control.moveAbove(Control) or Control.moveBelow(Control) + Control.layout() to avoid total refresh.
See: http://dev.eclipse.org/newslists/news.eclipse.platform.swt/msg09649.html
Test code: