can I combine SWT GridLayout and FillLayout

前端 未结 2 1172
深忆病人
深忆病人 2021-02-06 12:43

I have an RCP/SWT application in which I\'m trying to construct a view out of existing composites. One is a FillLayout composite, the other uses GridLayout.

I\'d to like

2条回答
  •  粉色の甜心
    2021-02-06 13:26

    Start setting a FormLayout to your outer composite. Place two other composites inside it, setting their FormData information to position them as you please. Then set those two composite's layouts (Grid and Fill, as you said).

    Here's some code to start. There's an image after it showing what it produces. You might also check out Eclipse's SWT Layouts view.

    Shell shell = new Shell();
    
    FillLayout fillLayout = new FillLayout();
    fillLayout.marginHeight = 5;
    fillLayout.marginWidth = 5;
    shell.setLayout( fillLayout );
    
    Composite outer = new Composite( shell, SWT.BORDER );
    outer.setBackground( new Color( null, 207, 255, 206 ) ); // Green
    
    FormLayout formLayout = new FormLayout();
    formLayout.marginHeight = 5;
    formLayout.marginWidth = 5;
    formLayout.spacing = 5;
    outer.setLayout( formLayout );
    
    Composite innerLeft = new Composite( outer, SWT.BORDER );
    innerLeft.setLayout( new GridLayout() );
    innerLeft.setBackground( new Color( null, 232, 223, 255 ) ); // Blue
    
    FormData fData = new FormData();
    fData.top = new FormAttachment( 0 );
    fData.left = new FormAttachment( 0 );
    fData.right = new FormAttachment( 10 ); // Locks on 10% of the view
    fData.bottom = new FormAttachment( 100 );
    innerLeft.setLayoutData( fData );
    
    Composite innerRight = new Composite( outer, SWT.BORDER );
    innerRight.setLayout( fillLayout );
    innerRight.setBackground( new Color( null, 255, 235, 223 ) ); // Orange
    
    fData = new FormData();
    fData.top = new FormAttachment( 0 );
    fData.left = new FormAttachment( innerLeft );
    fData.right = new FormAttachment( 100 );
    fData.bottom = new FormAttachment( 100 );
    innerRight.setLayoutData( fData );
    
    shell.open();
    

    Code output

提交回复
热议问题