Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Lost with layout methods and parameters...(Do not understand why the layout does not cascade down through)
Lost with layout methods and parameters... [message #1138959] Tue, 15 October 2013 12:44 Go to next message
hortiz Mising name is currently offline hortiz Mising nameFriend
Messages: 96
Registered: July 2009
Member
Hi,

The javadoc says about the layout method with two boolean parameters that if the second argument is set to true "the layout will cascade down through all child widgets in the receiver's widget tree, regardless of whether the child has changed size".

So I do not understand why in my snippet a click on the "Layout shell" button does not trigger any layout method of MyComposite instance whereas a click on the "Layout composite" button does...

package benchmark;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class TestLayoutShell {

	private Shell shell;
	private MyComposite composite;
	
	public static void main (String[] args) {		
		TestLayoutShell test = new TestLayoutShell();
		test.run();
	}
	
	private void run() {
		Display display = new Display();
		shell = new Shell(display);
		shell.setLayout(new GridLayout(3, false));
		
		composite = new MyComposite(shell, SWT.BORDER);
		composite.setLayoutData(new GridData(100, 100));
		
		Button layoutButton = new Button(shell, SWT.PUSH);
		layoutButton.setText("Layout shell");
		layoutButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
				shell.layout(true, true);
			}
		});
		
		Button layout2Button = new Button(shell, SWT.PUSH);
		layout2Button.setText("Layout composite");
		layout2Button.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent arg0) {
				composite.layout(true, true);
			}
		});

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



package benchmark;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

public class MyComposite extends Composite {

	public MyComposite(Composite parent, int style) {
		super(parent, style);
	}

	public void layout() {
		super.layout();
                System.out.println("layout()");
	}

	public void layout(boolean arg0, boolean arg1) {
		super.layout(arg0, arg1);
		System.out.println("layout(boolean arg0, boolean arg1)");
	}

	public void layout(boolean arg0) {
		super.layout(arg0);
		System.out.println("layout(boolean arg0)");
	}

	public void layout(Control[] arg0, int arg1) {
		super.layout(arg0, arg1);
		System.out.println("layout(Control[] arg0, int arg1)");
	}

	public void layout(Control[] arg0) {
		super.layout(arg0);
		System.out.println("layout(Control[] arg0)");
	}
}




Thanks in advance for your help,
Helene
Re: Lost with layout methods and parameters... [message #1159517 is a reply to message #1138959] Mon, 28 October 2013 15:46 Go to previous message
hortiz Mising name is currently offline hortiz Mising nameFriend
Messages: 96
Registered: July 2009
Member
Hi again,

I found the answer to my question using SWT source code to understand why the layout methods of the Composite class were not called.
Actually, the layout method called on the Shell instance really "cascade down through all child widgets" but without calling layout method on child composites but by directly calling layout method of the Layout class.



Previous Topic:SashForm -> ExpandBar -> Table
Next Topic:docking windows/views
Goto Forum:
  


Current Time: Tue Apr 23 15:59:20 GMT 2024

Powered by FUDForum. Page generated in 0.03275 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top