简体   繁体   中英

How to add a group out of a composite in SWT?

I have a filter composite in parent. My example image is here:

在此处输入图片说明

I want to add a group out of this filter composite. My example code is below:

// create parent layout
    GridLayout parentLayout = new GridLayout(1, true);
    parent.setLayout(parentLayout);         

    // design filter composite layout
    Group grp = new Group(parent, SWT.NONE);

    RowLayout grdLay = new RowLayout();

    GridData grdData = new GridData();

    grp.setLayoutData(grdData);

    grp.setLayout(grdLay);

    Composite grpComp = new Composite(grp,SWT.NONE);

    GridData gdData = new GridData();       

    RowLayout grplayout = new RowLayout();

    grpComp.setLayout(grplayout);

    grpComp.setLayoutData(gdData);

    Composite filterComposite = new Composite(grpComp, SWT.NONE);
    GridData gd_filterComposite = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd_filterComposite.widthHint = 1611;
    gd_filterComposite.heightHint = 42;
    filterComposite.setLayoutData(gd_filterComposite);

    RowLayout filterCompositeLayout = new RowLayout();
    filterCompositeLayout.type = SWT.VERTICAL;
    filterCompositeLayout.marginHeight = 5;
    filterCompositeLayout.center = true;
    filterCompositeLayout.fill = true;
    filterCompositeLayout.justify = true;
    filterCompositeLayout.wrap = true;
    filterComposite.setLayout(filterCompositeLayout);

    filterCompositeLayout.spacing = 20;

But I had an error. My error image is here:

在此处输入图片说明

How can I achive this? Can anybody give some advice? Thank you.

For controls which are part of a RowLayout the layout data must be RowData.

So

RowData gdData = new RowData();

because grpComp is part of the RowLayout set on grp

and similarly the filterComposite layout data should be RowData .

You must always match a control's layout data to the layout of the Composite which contains the the control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM