Search code examples
eclipseswte4

How to design like below picture using SWT which is fixed in all display screen size?


I am trying to design just like below image using swt. I used FormLayout where I need to give width and height which is fixed for all screen size. But i want to resize based on screen size. How do I implemented it?

image


Solution

  • You can do this with GridLayout using enough intermediate composites:

    // Assumes 'parent' has FillLayout which will be the case for an e4 part
    
    Composite outer = new Composite(parent, SWT.NONE);
    
    outer.setLayout(new GridLayout());
    
    Composite intermediate = new Composite(outer, SWT.NONE);
    intermediate.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    
    intermediate.setLayout(new GridLayout());
    
    Composite inner = new Composite(intermediate, SWT.NONE);
    inner.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
    
    inner.setLayout(new GridLayout(4, false));
    
    Label label1 = new Label(inner, SWT.LEAD);
    label1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
    label1.setText("TopLevelPath");
    
    Text text1 = new Text(inner, SWT.SINGLE | SWT.BORDER);
    text1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    
    Label endLabel = new Label(inner, SWT.PUSH);
    endLabel.setText("but1");
    
    endLabel = new Label(inner, SWT.PUSH);
    endLabel.setText("but2");
    
    Label label2 = new Label(inner, SWT.LEAD);
    label2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
    label2.setText("Alt TopLevelPath (optional)");
    
    Text text2 = new Text(inner, SWT.SINGLE | SWT.BORDER);
    text2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));